UIActionSheet 无效参数不满足:view != nil
在导航堆栈上弹出一些视图控制器后,我收到此错误,最后我通过操作表提出问题。我收到错误参数不满足 view != nil
的要求,这让我发疯,因为当我在调用操作表之前进行检查时,事实上它不是一个 nil
值。
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];
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];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您尝试在其中显示 UIActionSheet 的视图很可能尚未附加到窗口。尝试在视图附加到窗口后调用 showInView。假设上面的代码是在视图控制器实现中,尝试在 viewDidLoad 而不是 loadView 中调用它。
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.
我不得不 [self PerformSelector: withObject: afterDelay:1.] 每次弹出之后,我猜它必须对视图的状态做一些事情。需要显示。
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.
showInView 也给了我 无效参数不满足:view != nil 异常..所以我尝试了
[self.view addSubview 操作表];
showInView 应该在 viewDidLoad 之后调用,所以如果添加 [actionSheet showInView:self.view];在 viewDidAppear 中,它不会崩溃..
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..
当我在 Xcode 4.6.2 中进行单元测试时,当它遇到应该显示 UIActionSheet 的行时,就会发生此错误。在旧版本的 Xcode 中不会出现这种情况。我认为这是因为类似的问题 - 在单元测试期间没有可以呈现的视图。
我通过编写测试来修改底层数据然后测试它来解决这个问题,而不是呈现一个操作表然后选择一个按钮,并向 Apple 提交错误报告。
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.