This question already has answers here:
Crash when pushing to another controller after `didFinishPickingMediaWithInfo`
                                
                                    (2个答案)
                                
                        
                                2年前关闭。
            
                    
当我运行此代码时,我得到一个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")
            }
        }

    }

}


是让myImage崩溃的应用程序。

感谢您的时间...

最佳答案

问题似乎在于以下几行:

viewVC.imageCours.image = myImage


如果imageCours是UIImageView,则可能尚未创建此视图。您应该只传递图像并将其设置在目标ViewController的viewDidLoad()中。

关于ios - Xcode 8 swift 3从URL加载图像并将其传递到segue目的地,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42930339/

10-08 21:05