UIActionSheet在iOS7 中的问题

今天,在代码中的- (void)viewDidLoad方法中直接调用如下代码:

 UIActionSheet* actSheet=[[UIActionSheet alloc]initWithTitle:@"想念是蓝色的" delegate:self cancelButtonTitle:@"确定" destructiveButtonTitle:@"删除" otherButtonTitles:@"取消", nil];

    [actSheet showInView:self.view];

UIActionSheet在iOS7 中的问题_第1张图片

尽然爆出了如下错误:

** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Sheet can not be presented because the view is not in a window: <UIView: 0x8cb3f70; frame = (0 0; 320 480); autoresize = RM+BM; layer = <CALayer: 0x8cb3680>>'

*** First throw call stack:


那么该怎么解决这个问题了,上网百度了下,都说

UIWindow* window=[UIApplication sharedApplication].keyWindow;

    if ([window.subviews containsObject:self.view]) {

        [actSheet showInView: self.view];

    }

    else

    {

       [actSheet showInViewwindow];

    }


我尝试了一下,还是不行。解决办法如下:

UIActionSheet在iOS7 中的问题_第2张图片


原文博客地址:http://www.haodaima.net/art/2901243

你可能感兴趣的:(view,sheet,ios7,UIActionSheet,can,the,be,not,presented,because)