UIActionSheet Invalid parameter not satisfying: vi

2019-04-16 16:41发布

I'm getting this error after popping some view controllers on a navigation stack, and at the end I get to ask a question through an action sheet. I'm getting the error parameter not satisfying view != nil, which drives me crazy because it-so facto is not a nil value when I check before calling the action sheet.

   if (self.view != nil) {
            NSLog(@"view is not nil");
        }
UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:@"title" delegate:nil cancelButtonTitle:@"cancel" destructiveButtonTitle:@"destructive" otherButtonTitles:nil];
    [actionSheet showInView:self.view];

4条回答
霸刀☆藐视天下
2楼-- · 2019-04-16 17:17

showInView was giving me Invalid parameter not satisfying: view != nil exception too.. so i tried [self.view addSubview action sheet];

showInView should be called after viewDidLoad so if add [actionSheet showInView:self.view]; in viewDidAppear , it won't crash..

查看更多
Juvenile、少年°
3楼-- · 2019-04-16 17:23

This error occurred in my unit tests in Xcode 4.6.2 when it hit a line that should present a UIActionSheet. It did not occur in older versions of Xcode. I think it is because of a similar issue - there is no view to present to during unit testing.

I worked around it by writing my test to modify the underlying data and then test it, rather than present an action sheet and then select a button, and submitted a bug report to Apple.

查看更多
Emotional °昔
4楼-- · 2019-04-16 17:24

I had to to a [self performSelector: withObject: afterDelay:1.] After each pop, I'm guessing it has to do something with the state of the view. In needs to be displayed.

查看更多
老娘就宠你
5楼-- · 2019-04-16 17:32

Very likely that the view you are attempting to display the UIActionSheet in is not attached to the window yet. Try calling showInView after the view is attached to a window. Assuming the above code is in view controller implementation, try calling it in viewDidLoad instead of loadView.

查看更多
登录 后发表回答