UIActionSheet Invalid parameter not satisfying: view != nil

跟風遠走 提交于 2019-12-06 15:50:58

问题


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];

回答1:


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.




回答2:


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.




回答3:


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




回答4:


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.



来源:https://stackoverflow.com/questions/9272734/uiactionsheet-invalid-parameter-not-satisfying-view-nil

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!