Qizijia
Qizijia

Reputation: 31

libc+abi.dylib: terminating with uncaught exception of type NSException

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {  
        let alert = SCLAlertView()  
        alert.addButton("A",target:self,selector: #selector(FirstViewController.firstButton))  
        alert.addButton("B",target:self,selector: #selector(FirstViewController.secondButton))  
        self.dismiss(animated: true, completion: {  
            alert.showSuccess(kSuccessTitle,subTitle: kSubtitle1)  
//            self.present(secondViewController,animated: true,completion: nil)  
        })  
    }  
    @objc func firstButton(info: [UIImagePickerController.InfoKey : Any])  
    {  
        let sb = UIStoryboard(name:"Main",bundle: Bundle.main)  
        let secondViewController = sb.instantiateViewController(withIdentifier: "view2") as! SecondViewController  
        secondViewController.infoFromViewOne = info[UIImagePickerController.InfoKey.editedImage] as? UIImage  
        secondViewController.flag = 0  
        self.present(secondViewController,animated: true,completion: nil)  
    }  
    @objc func secondButton()  
    {  
        let sb = UIStoryboard(name:"Main",bundle: Bundle.main)  
        let thirdViewcontroller = sb.instantiateViewController(withIdentifier: "SecondViewController") as! ViewController  
        self.present(thirdViewcontroller,animated: true,completion: nil)  
    }  

This is my code, My desire result is that when I click the first button, the page jump to "SecondViewcontroller" and the image in the SecondViewcontroller's imageView is the photo I just select.

But now, after selecting the photo and click the first button, the app crashes at AppDelegate.swift, with an error message: "libc++abi.dylib: terminating with uncaught exception of type NSException"

What should I do to make it correct?

Upvotes: 0

Views: 626

Answers (1)

Zeeshan Ahmed
Zeeshan Ahmed

Reputation: 864

private var infoFromViewOne: UIImage()
    var _infoFromViewOne:UIImage {
    set{ 
         _infoFromViewOne = newValue 
    }
    get{ 
         return _infoFromViewOne
    }
}

replace it with this remove error if because I don't have that exact code snippet right now but maybe can provide you tomorrow.

Upvotes: -2

Related Questions