views:

240

answers:

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.

+1  A: 

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.

Shaggy Frog
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.
Michael Rowe
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.
Shaggy Frog
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.
Michael Rowe
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.
Michael Rowe
Add a line like `UIView* v = self.view;` and set a breakpoint. Is `v` equal to `nil`?
Shaggy Frog
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?
Michael Rowe
Ok.. I figured it out- [actionSheet showInView:self.parentViewController.view];
Michael Rowe
A: 

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

Saurabh Verma
Thanks.. I've been able to resolve by using the parent pointer. Will flag this for future checks.
Michael Rowe