我的程序能够成功编译,但是当我点击按钮时就会崩溃。以下是viewController.swift文件的内容:
import UIKit
class ViewController: UIViewController, UIActionSheetDelegate{
@IBOutlet var button:UIButton
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func buttonPressed(AnyObject) {
let choice = UIActionSheet(title: "Select source", delegate: self, cancelButtonTitle: "Cancel", destructiveButtonTitle: nil, otherButtonTitles:"camera", "libary")
choice.showInView(self.view)
}
}
这个错误出现在这一行:
let choice = UIActionSheet(title: "Select source", delegate: self, cancelButtonTitle: "Cancel", destructiveButtonTitle: nil, otherButtonTitles:"camera", "library")
以下是错误信息:
EXC_BAD_ACCESS (code=2, address=0x0)
我尝试将 let 改为 var,用不同的模拟器运行,但结果仍然相同。