Jim Hankins
Jim Hankins

Reputation: 1073

App crashes frequently at time when UIActionSheet would be presented

I am getting the following error intermittently when a call is made to display an action sheet.

Assertion failure in -[UIActionSheet showInView:]

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: view != nil'

Now in this case I've not changed screens. The UIActionSheet is presented when a local notification is fired and I have an observer call a local method on this view as such: I have the property marked as strong. When the action sheet is dismissed I also set it to nil. I am using a story board for the UI. It's fairly repeatable to crash it, perhaps less than 5 tries. (Thankfully I have that going for me). Any suggestions what to try next? I'm really pulling my hair out on this one. Most of the issues I've seen on this topic are pointing to the crash occurring once the selection is made. In my case it's at presentation and intermittently. Also for what it's worth, this particular view is several stacks deep in an embedded navigation controller. Home>tableview>detail select>viewController in question. This same issue occurs so far in testing on iOS 5.1 and iOS 6. I'm presuming it's something to do with how the show InView is being targeted.

self.actionSheet = [[UIActionSheet alloc]
                            initWithTitle:@"Select Choice" delegate:self cancelButtonTitle:@"Not Yet" destructiveButtonTitle:@"Do this Now" otherButtonTitles:nil];

[self.actionSheet showInView:self.parentViewController.tabBarController.view];

Upvotes: 0

Views: 1604

Answers (2)

Jim Hankins
Jim Hankins

Reputation: 1073

The answer to the problem was that I was not removing an NSNotificationCenter observer. It only became obvious when the change was made recommended by @zsnow which resolved the crash but resulted in duplicated UIAlertSheet dialogs being presented.

In my particular case adding the following resolved my issue. Thanks for everyone's help. The suggestions got me close enough to cross the finish line.

-(void)viewWillDisappear:(BOOL)animated {


[[NSNotificationCenter defaultCenter] removeObserver:self];

}

Upvotes: 0

zachjs
zachjs

Reputation: 1748

Based on your code, it would seem that self.tabBarController or self.tabBarController.tabBar are not set when this is called.

Try using:

[self.actionSheet showInView:self.view];

Edit: fixed error

Edit 2: Making the action sheet appear on top of a tab bar

[self.actionSheet showInView:[[UIApplication sharedApplication].delegate window]];

Upvotes: 1

Related Questions