UIActionSheet Crashes on iPad / not iPhone
Asked Answered
S

6

2

When I look in the console I get this message

2010-09-18 17:04:05.284 Wasted Time[8998:207] *** Assertion failure in -[UIActionSheet showInView:], /SourceCache/UIKit_Sim/UIKit-1145.66/UIAlert.m:7073
2010-09-18 17:04:05.286 Wasted Time[8998:207] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: view != nil'
2010-09-18 17:04:05.286 Wasted Time[8998:207] Stack: (
    42272848,
    43430700,
    42010379,
    811796,
    3796273,
    3862560,
    9631,
    3616645,
    3688229,
    3682846,
    3690662,
    3686119,
    4983946,
    71264534,
    71263781,
    71207378,
    71206706,
    3003734,
    3030334,
    3011831,
    3043800,
    51265916,
    41552028,
    41547944,
    3002913,
    3036018,
    8314
)
terminate called after throwing an instance of 'NSException'

The code is as follows:

- (void)viewDidLoad {
    BOOL    continueYesNo;
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    continueYesNo = [prefs boolForKey:@"keyContinueMeeting"];   
    if (continueYesNo) {
        NSString *message_continue = [[NSString alloc] initWithFormat:@"Do you want to Continue the Prior Meeting"];
        UIActionSheet *actionSheet = [[UIActionSheet alloc] 
            initWithTitle:message_continue 
            delegate:self
            cancelButtonTitle:@"Reset" 
            destructiveButtonTitle:@"Continue"
            otherButtonTitles:nil];
        [actionSheet showInView:self.view];
        [actionSheet release];
        [message_continue release];
    }
}

It runs fine both in the iPhone and in the iPhone simulator, but crashes in the iPad simulator.

Statolith answered 18/9, 2010 at 21:8 Comment(0)
K
5

The error message says:

Invalid parameter not satisfying: view != nil

Likely from this line:

[actionSheet showInView:self.view];

Since you say this works on iPhone but not iPad, that means that the code path the iPad takes to get to this line is probably different than the code path the iPhone takes to get to this line. Which means that the view controller's view property is probably not set for the iPad.

My guess: you forgot to hook up the view outlet in Interface Builder for the iPad version of the xib this view controller is using.

Koerlin answered 18/9, 2010 at 21:14 Comment(7)
Thanks for the quick response. This makes a lot of sense, but I do not have a separate NIB file for the iPad version. In a prior version of the Application I had used the command ->Project, Upgrade current target for iPad.Statolith
Well, your error message says an assert is raised from [UIActionSheet showInView:] because self.view is nil. Why is it nil? Start there and work your way up.Koerlin
Thanks! I have created new XIB's for each of the 3 TabView's in my TabView Controller.. allows me to create a much better iPad interface.. your question got me in the right direction... however when I created new XIB's for the iPad versions and connected them to the mainwindow-ipad.xib (the TabViewController), I now get a new / different runtime error will post a new question for that one.Statolith
OK, now I've gotten that working... miswired. And I am back to the showInView error above. This may be a bit of a neophyte question, how do I work my way back up? I have stepped thru the debugger and I am not sure how to see where self.view is pointing.Statolith
Add a line like UIView* v = self.view; and set a breakpoint. Is v equal to nil?Koerlin
Thanks.. The line after the UIView* v=self.view is the one that will crash. In the debugger v has a value of 0x296364f - which looks like a memory pointer. It's UIResponder has a valid Pointer also - when I look at the details in the expression window. Perhaps I need to get the parent view? But that doesn't make sense.. Self is the class I am in, which is the view which just executed viewDidLoad, so should not self return that view?Statolith
Ok.. I figured it out- [actionSheet showInView:self.parentViewController.view];Statolith
I
3

I also had this problem but I was using [actionSheet showInView:[self.view window]]; (to fix another bug where only half the cancel button is selectable).

Now I conditionally change this to [actionSheet showInView:self.view]; on the iPad.

I found it's best not to the style to UIActionSheetStyleBlackTranslucent on the iPad either – the iPad has it's own style, and setting this seems to add the cancel button (which by default on the iPad is not shown).

Indamine answered 10/11, 2010 at 11:37 Comment(2)
OK.. gonna give this a try, I found that on latest build my .parentViewController trick is not working... App is just crashing every time...Statolith
NB: Using the window will cause iPhone landscape to display the action sheet incorrectlyDisdain
E
0

do like this:

[self performSelectorOnMainThread:@selector(choosePhoto) withObject:nil waitUntilDone:NO];

-(void)choosePhoto
{

    UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:@""
                                                  delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil
                                         otherButtonTitles:@"Take Photo", @"Choose from gallery", nil];
    actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
    actionSheet.tag = 1;
    [actionSheet showInView:self.view];
    [actionSheet release];
}

Worked for me

Effie answered 27/9, 2010 at 14:29 Comment(2)
Thanks.. I've been able to resolve by using the parent pointer. Will flag this for future checks.Statolith
well.. this didn't seem to work on latest version of xCode... app traps with both my above solution of [actionSheet showInView:self.parentViewController.view]; and both work arounds listed... Back to the drawing board...Statolith
A
0

I believe the problem is that the view has not appeared yet. Put it in viewDidAppear: and it should work fine.

Astrogation answered 27/1, 2012 at 0:3 Comment(0)
H
0

For those like me that may be using UIActionSheet slightly differently than in the original question, but still failing on iPad, I had been using:

[actionSheet showFromRect:m_view.bounds inView:m_view animated:YES];
[actionSheet release];

...which works on iPhone but fails on iPad.

This example works in my particular app on both devices:

[actionSheet showInView:m_view];
[actionSheet release];

Regards, David

Hephaestus answered 30/8, 2012 at 16:48 Comment(0)
G
0

This is an old question, but I encountered the same problem today. I have a xib file for a UIViewController that's common to iPhone and iPad, and the showInView method on the UIActionSheet was causing the iPad app to crash.

Turned out calling showInView in the viewDidAppear, instead of viewDidLoad fixed it for me. Perhaps all IB connections weren't made by the time viewDidLoad was called on iPad.

(my UIViewController was being pushed onto a UINavigationController, so I wonder if the increased animation time is what caused the whole issue_

Grecism answered 6/8, 2013 at 21:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.