ios - Swift Alert 弹出窗口出现在模拟器 iphone 4s(8.1) 中,而不是 iphone 4s (7.1)

标签 ios xcode swift uialertcontroller

我编写了代码,在单击按钮时显示一个简单的警报弹出窗口。在模拟器 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 ”常量的代码)以绿色突出显示,并显示消息“Thread 1: EXC_BAD_ACCESS(Code=1,address=0x10)”

如果有任何帮助,我将不胜感激

最佳答案

UIAlertController 适用于 iOS >= 8.0

您必须使用适用于 iOS <8.0 的 UIAlertView

关于ios - Swift Alert 弹出窗口出现在模拟器 iphone 4s(8.1) 中,而不是 iphone 4s (7.1),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28834395/

相关文章:

objective-c - UIWebView 中的 YouTube 只播放一次

ios - 如何在 swift 3 中为多个值实现模型类?

xcode - 如何在 Xcode 4.5 "Command Line Tool"项目中设置工作逻辑单元测试目标?

ios - 应用程序未覆盖 iPad 上的整个屏幕

swift - 隐藏导航栏时更改状态栏颜色

ios - 按位右移 >> 在 Objective-C 中

ios - 如何在没有用户交互的情况下将视频上传到 Facebook? (或在后台)获得公开 session 后

ios - Xcode 8.3.2 上的词法或预处理器问题

ios - prepareForSegue 编译器错误

ios - 在 Swift 版本 2.0 中撰写电子邮件问题