UIActionSheet无效参数不满足:view!= nil

the*_*end 0 cocoa-touch uiviewcontroller uiview uinavigationcontroller uiactionsheet

我在导航堆栈上弹出一些视图控制器后出现此错误,最后我通过操作表询问问题.我得到的错误参数不满意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];
Run Code Online (Sandbox Code Playgroud)

Sun*_*wda 5

您尝试显示UIActionSheet的视图很可能尚未附加到窗口.将视图附加到窗口后尝试调用showInView.假设上面的代码在视图控制器实现中,尝试在viewDidLoad而不是loadView中调用它.