3
votes

I am working through "Beginning iPad Application Development" and am getting hung up in Chapter 3 where I have created a project that works with an Action Sheet.

As it stands now, my application loads into the simulator just fine with no errors that I am aware of, but as it runs, it crashes with the following errors showing up in the debugger window:

2010-05-31 19:44:39.703 UsingViewsActionSheet[49538:207] *** Assertion failure in -[UIActionSheet showInView:], /SourceCache/UIKit_Sim/UIKit-1145.66/UIAlert.m:7073

2010-05-31 19:44:39.705 UsingViewsActionSheet[49538:207] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: view != nil

'

I am sure that this is the block where the app breaks based upon my use of breakpoints.

//Implement viewDidLoad to do additional setup after loading the view, typically from a nib.

- (void)viewDidLoad { UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:@"This is my Action Sheet!" delegate:self cancelButtonTitle:@"OK" destructiveButtonTitle:@"Delete Message!" otherButtonTitles:@"Option 1", @"Option 2", @"Option 3", nil];

[action showInView:self.view];  // <-- This line seems to trigger the crash....
[action release];
[super viewDidLoad];

}

Am I missing something obvious, or is there more to the problem than is shown here? I have looked at the abstract for showInView and cannot divine anything there yet.

I appreciate any and all asssitance.

Regards,

Steve O'Sullivan

5

5 Answers

11
votes

Within the viewDidLoad method the view is not setup entirely. The window property is not wired up.

NSLog(@"View: %@; Window: %@",[self.view description], [self.view.window description]);

will probably show that window is null/nil.

Depending on your design, you may have luck with simply queueing it on the main thread:

-(void) showMyActionSheet
{
    UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:@"This is my Action Sheet!" delegate:self cancelButtonTitle:@"OK" destructiveButtonTitle:@"Delete Message!" otherButtonTitles:@"Option 1", @"Option 2", @"Option 3", nil]; 
    [action showInView:self.view];
    [action release];
}

- (void)viewDidLoad 
{
    [super viewDidLoad]; 
    [self performSelectorOnMainThread:@selector(showMyActionSheet) withObject:nil waitUntilDone:NO];
}
1
votes

I've just had the same problem. I was converting an existing iPhone app to run universal. I have several buttons that called UIAlertViews that work fine but I have a button that calls an actionsheet. It was generating the same error. In IB in my ipadview.xib in my view controller i had mislinked "view" to window when i should have linked it to the button. It now works fine. Hope this helps. (ps im a complete novice so forgive if this doesnt help) Neil

0
votes

I was just working through the same chapter and the book's author addresses it here http://p2p.wrox.com/book-beginning-ipad-application-development/79379-ch-3-usingviews-alert-actionsheet.html though if I were you I would vote Eiko's response as the answer since it accomplishes the behavior the example is going for, whereas the authors has you create a button that you clicked after the application launches to see the sheet.

0
votes

Just for any late comers to this topic, this is still an issue in 5.0 (9A334) iPad simulator and physical devices (iPads).

The answer by Eiko remains correct.

0
votes

I have fixed assertion failure for ActionSheet recently like this:

UIWindow* window = [[[UIApplication sharedApplication] delegate] window];
    if ([window.subviews containsObject:self.view]) {
        [action showInView:self.view];
    } else {
        [action showInView:window];
    }

It works fine for me.