我编写了代码,以在单击按钮时显示一个简单的警报弹出窗口。在模拟器iPhone 4s(8.1)中尝试该应用程序时,它可以按预期工作,但是在模拟器iPhone 4s(7.1)中尝试时,该应用程序始终崩溃。
这里的代码:
@IBAction func buttonPressed(sender:UIButton){
let controller = UIAlertController(title: "This is a title", message: "Hello, my friend", preferredStyle: UIAlertControllerStyle.Alert)
let cancelAction = UIAlertAction(title: "Phew!", style: .Cancel, handler: nil)
controller.addAction(cancelAction)
self.presentViewController(controller, animated: true, completion: nil)
}
这是错误消息:
第一行代码(创建“ controller”常量的代码)以绿色突出显示,并显示消息“线程1:EXC_BAD_ACCESS(Code = 1,address = 0x10)”。
我将不胜感激任何帮助
不幸的是,UIAlertController仅在iOS 8.0和更高版本中可用,这里是文档,并且在右侧进行了说明:https : //developer.apple.com/library/ios/documentation/UIKit/Reference/UIAlertController_class/#//apple_ref/ doc / uid / TP40014538-CH1-SW2
我相信它代替了现在不推荐使用的UIAlertView,可以在Apple文档中找到:https : //developer.apple.com/library/ios/documentation/UIKit/Reference/UIAlertView_Class/index。 html#// apple_ref / occ / cl / UIAlertView
Swift不喜欢旧的,而是考虑和“ if”子句,并使用该应用为相应的iOS系统创建UIAlertView和UIAlertController。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句