ios actionsheet showinview导致崩溃解决方法
2014-11-10 16:56
423 查看
如果在代码中调用加入actionsheet的功能
正常是可以调出来
这个选择菜单的
如果controller.view还没有添加到window的时候,系统就会报错崩溃。
报错内容如下:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Sheet can not be presented because the view is not in a window: <UIView: 0xce7df00; frame = (0 0; 320 480); autoresize = RM+BM; layer = <CALayer: 0xce51bb0>>'
******
这是因为在controller的viewdidload加入了actionview showinview的方法,但这个时候其实view还没有加入到window,不符合actionsheet的要求。
网上有其他一些解决方法,说加入到window中,或者检查下window的subviews是否已经包含当前view
我不是很建议使用上述方法,没有解决我的问题。
后来改在viewdidappear上去调用actionview showinview,这个时候view已经加入到window上了,就没有上述问题。
参考的资料:
http://blog.csdn.net/hwak_07/article/details/27107319
http://stackoverflow.com/questions/18932544/nsinvalidargumentexception-reason-sheet-can-not-be-presented-because-the-vi
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:ASButtonTitleCancel destructiveButtonTitle:nil otherButtonTitles:ASButtonTitleCamera, ASButtonTitleLibrary,nil]; actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque; [actionSheet showInView:controller.view];
正常是可以调出来
这个选择菜单的
如果controller.view还没有添加到window的时候,系统就会报错崩溃。
报错内容如下:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Sheet can not be presented because the view is not in a window: <UIView: 0xce7df00; frame = (0 0; 320 480); autoresize = RM+BM; layer = <CALayer: 0xce51bb0>>'
******
这是因为在controller的viewdidload加入了actionview showinview的方法,但这个时候其实view还没有加入到window,不符合actionsheet的要求。
网上有其他一些解决方法,说加入到window中,或者检查下window的subviews是否已经包含当前view
我不是很建议使用上述方法,没有解决我的问题。
后来改在viewdidappear上去调用actionview showinview,这个时候view已经加入到window上了,就没有上述问题。
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. //原先在这里添加actionsheet并showinview:self.view } - (void)viewDidAppear:(BOOL)animated { //修改后在这里添加actionsheet并showinview:self.view }
参考的资料:
http://blog.csdn.net/hwak_07/article/details/27107319
http://stackoverflow.com/questions/18932544/nsinvalidargumentexception-reason-sheet-can-not-be-presented-because-the-vi
相关文章推荐
- ios tableView那些事 (十六) UITableView中Cell重用机制导致内容重复解决方法
- ios UITableView中Cell重用机制导致内容重复解决方法
- IOS WebView修改contentInset 导致webview长按弹出菜单跳动的解决方法
- iOS开发笔记--解决UITableView中Cell重用机制导致内容出错的方法总结
- IOS开发 UITableView中Cell重用机制导致内容重复解决方法
- No resource identifier found for attribute'showAsAction' in package '...... '解决方法之一
- iOS中3DTouch预览导致TableView滑动卡顿问题解决的方法
- iOS 8中CLLocationManager及MKMapView showUserLocation失败的解决的方法
- ios tableView那些事 (十六) UITableView中Cell重用机制导致内容重复解决方法
- ios tableView那些事 (十六) UITableView中Cell重用机制导致内容重复解决方法
- java.lang.NullPointerException Exception details are logged in Window > Show View > Error Log 正确解决方法
- ios tableView那些事 UITableView中Cell重用机制导致内容重复解决方法
- iOS 同一页面加载上百张图片,迅速滑动时导致内存暴涨程序崩溃的参考解决方法
- iOS开发:Xcode 7之后viewForHeaderInSection、viewForFooterInSection设置内容不产生效果的解决方法
- ios tableView那些事 (十六) UITableView中Cell重用机制导致内容重复解决方法
- sharepoint 2010 列表的数据表视图无法使用 the list cannot be displayed in datasheet view 解决方法
- ios actionsheet 跟 imagepickercontroller冲突的问题解决方法
- iOS开发笔记--解决UITableView中Cell重用机制导致内容出错的方法总结
- ios tableView那些事 (十六) UITableView中Cell重用机制导致内容重复解决方法
- ios tableView那些事 (十六) UITableView中Cell重用机制导致内容重复解决方法