我有以下视图控制器.它只是从文本字段中读取要在a中显示的值UIAlertView.
import UIKit
class ViewController: UIViewController {
@IBOutlet var textField: UITextField!
@IBAction func pressButton(sender: UIButton) {
let name = textField.text
let alert = UIAlertView(
title: "Hello!",
message: "How are you today, \(name). I'm lovely!",
delegate: nil,
cancelButtonTitle: "Thanks!"
)
alert.show() // EXC_BAD_ACCESS
}
}
Run Code Online (Sandbox Code Playgroud)
为什么会alert.show()崩溃EXC_BAD_ACCESS?这是我的实例发生了什么UIAlertView?为什么它alert不像我认为它应该是?
尝试使用var而不是lat如下
var alert = UIAlertController(title: "Title", message: "Message", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2567 次 |
| 最近记录: |