我想扫描一个 QR 码(执行此示例:http://humberaquino.me/qrcode-scanning-in-swift/),但是我对这段代码有疑问:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let barcodeViewController: BarcodeViewController = segue.destinationViewController as! BarcodeViewController
barcodeViewController.delegate = self
}
我明白了:
当我将其更改为 as!
时,我得到:
Thread 1: signal SIGABRT on this line.
最佳答案
如果您在该 View Controller 上有多个 segue,则可能是另一个正在触发。检查 segue.identifier 是确保你在正确的方法上的一种方法。如果行为基于类,您可以这样做:
if let barcodeViewController = segue.destinationViewController as? BarcodeViewController
{
barcodeViewController.delegate = self
}
关于ios - prepareForSegue 编译器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34832966/