当我运行此代码时,我收到 EXC_BAD_INSTRUCTION,但我不明白为什么:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
if (segue.identifier == "tblancSegue"){
let viewVC = segue.destination as! DetailCoursViewController
//viewVC.delegate = self
viewVC.nomDuCours = self.cours1Lbl.text
do {
let myImage = try UIImage(data: NSData(contentsOf: NSURL(string:self.cours1Image!) as! URL) as Data)
viewVC.imageCours.image = myImage
} catch {
print("foirage")
}
}
}
}
let myImage 导致应用程序崩溃。
感谢您的宝贵时间...
最佳答案
问题似乎出在以下行:
viewVC.imageCours.image = myImage
如果imageCours
是一个UIImageView,那么这个View可能还没有创建。您应该仅传递图像并将其设置在目标 ViewController 的 viewDidLoad()
中。
关于ios - Xcode 8 swift 3 从 URL 加载图像并将其传递到 segue 目的地,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42930339/