0
votes
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?

1
was there any other error in the console as well? i belive their must be another line of description as well.Zeeshan Ahmed
Share the complete crash report i.e. right after NSExceptionShubham Bakshi
@ZeeshanAhmed Nope,There is just a line error at console齐子佳
show me the declaration of this "infoFromViewOne " vaiableZeeshan Ahmed
@ShubhamBakshi I'm sure there was no error message after that.齐子佳

1 Answers

-2
votes
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.