UIActionSheet Crashes on iPad / not iPhone

前端 未结 6 562
-上瘾入骨i
-上瘾入骨i 2021-01-03 16:24

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/UI         


        
相关标签:
6条回答
  • 2021-01-03 16:30

    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

    0 讨论(0)
  • 2021-01-03 16:36

    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).

    0 讨论(0)
  • 2021-01-03 16:43

    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

    0 讨论(0)
  • 2021-01-03 16:45

    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.

    0 讨论(0)
  • 2021-01-03 16:47

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

    0 讨论(0)
  • 2021-01-03 16:51

    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_

    0 讨论(0)
提交回复
热议问题