iPad点击按钮弹出alert对话框崩溃
来源:互联网 发布:阿瓦隆b族洗发水 知乎 编辑:程序博客网 时间:2024/05/17 09:31
错误信息
Terminating app due to uncaught exception ‘NSGenericException’, reason: ‘Your application has presented a UIAlertController () of style UIAlertControllerStyleActionSheet. The modalPresentationStyle of a UIAlertController with this style is UIModalPresentationPopover. You must provide location information for this popover through the alert controller’s popoverPresentationController. You must provide either a sourceView and sourceRect or a barButtonItem. If this information is not known when you present the alert controller, you may provide it in the UIPopoverPresentationControllerDelegate method -prepareForPopoverPresentation.’
解决办法
http://stackoverflow.com/questions/26039229/swift-uialtertcontroller-actionsheet-ipad-ios8-crashes
修改前代码
@IBAction func alert(sender: UIButton) { let alertController = UIAlertController(title: "My first app", message: "Hello World", preferredStyle: .ActionSheet) alertController.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil)) self.presentViewController(alertController, animated: true, completion: nil) }
修改后代码
@IBAction func alert(sender: UIButton) { let alertController = UIAlertController(title: "My first app", message: "Hello World", preferredStyle: .ActionSheet) //ipad使用,不加ipad上会崩溃 if let popoverController = alertController.popoverPresentationController { popoverController.sourceView = sender popoverController.sourceRect = sender.bounds } alertController.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil)) self.presentViewController(alertController, animated: true, completion: nil) }
- iPad点击按钮弹出alert对话框崩溃
- Jquery点击按钮弹出alert
- 点击按钮弹出对话框
- 点击按钮弹出对话框
- 点击按钮,弹出对话框
- Delphi中点击网页弹出的Alert对话框的确定按钮
- 点击按钮弹出下载对话框
- 点击按钮弹出对话框提示
- Excel点击按钮弹出对话框
- java点击按钮弹出对话框
- Android点击按钮弹出对话框
- dojo点击按钮弹出对话框
- 点击UpdatePanel中的按钮弹出javascript对话框
- MFC 点击按钮,弹出另一个对话框
- 点击UpdatePanel中的按钮弹出javascript对话框
- MFC 点击按钮,弹出另一个对话框
- MFC 点击按钮,弹出另一个对话框
- MFC 点击按钮,弹出另一个对话框
- pdf.js使用
- 面试题---------分层初始化的顺序
- html5 中新的naturalWidth和naturalHeight属性
- MySQL索引背后的数据结构及算法原理
- myBatis批量添加,修改和删除
- iPad点击按钮弹出alert对话框崩溃
- web performace
- 用 GStreamer 简化 Linux 多媒体开发
- Mysql忘记密码解决方案
- 从高版本JDK换成低版本JDK报错Unsupported major.minor version 52.0
- 数据结构 —— 链表实现多项式加减乘
- 电子地图中要素旋转功能实现
- 杭电 2049
- Xcode4.2 SVN代码管理 使用方法