0

I have been trying to figure out this for a few days now. I have done a ton of searching within google and stack but have not been able to find something that works or makes sense. I am new to Swift but have some programming background.

Currently this part of the app takes a picture, displays it on the current viewcontroller(VCPhoto), moves to another controller, displays an animation viewcontroller(VCQScan), then moves to a result viewcontroller(VCResult). I am trying to move the image from the VCPhoto to VCResult. One answer I found was this one

Passing Image to another View Controller (Swift)

This, in my code, returns a null value in the next viewcontroller.

VCPhoto {

@IBOutlet var butTakePhoto: UIButton!
@IBOutlet var butSkip: UIButton!
@IBOutlet var scanCatB: UIButton!
@IBOutlet var previewPhoto: UIImageView!
let picker = UIImagePickerController()

override func viewDidLoad() {
    super.viewDidLoad()

    butTakePhoto.addTarget(self, action: #selector(VCPhoto.buttonPressed(_:)), for: .touchUpInside)
    butSkip.addTarget(self, action: #selector(VCPhoto.buttonPressed(_:)), for: .touchUpInside)
    scanCatB.addTarget(self, action: #selector(VCPhoto.buttonPressed(_:)), for: .touchUpInside)

    picker.delegate = self
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

public func buttonPressed (_ sender: AnyObject?){

    if sender === butTakePhoto {
        if UIImagePickerController.isSourceTypeAvailable(.camera) {
                picker.allowsEditing = false
                picker.sourceType = UIImagePickerControllerSourceType.camera
                picker.cameraCaptureMode = .photo
                picker.modalPresentationStyle = .fullScreen
            present(picker,animated: true,completion: nil)
        }
    }
    if sender === scanCatB {

        performSegue(withIdentifier: "sSegue", sender: UIButton.self)
    }
    if sender === butSkip {
        performSegue(withIdentifier: "Result", sender: nil)
    }

}
    func imagePickerController(
        _ picker:                           UIImagePickerController,
        didFinishPickingMediaWithInfo info: [String : Any])
    {
        picker.dismiss(animated: true, completion: nil)
        let image = info[UIImagePickerControllerOriginalImage] as? UIImage
        previewPhoto.image = image

        //butScan.isHidden=false
        //butSkip.isHidden=true
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

    if segue.identifier == "sSegue" {
        let dvc = segue.destination as? VCQScan
        dvc?.newImage = previewPhoto.image
    }

VCScan {

@IBOutlet var catScanImage: UIImageView!
@IBOutlet weak var browsingImage: UIImageView!
var newImage: UIImage!


override func viewDidLoad() {
    super.viewDidLoad()

    browsingImage.image = newImage


    Timer.scheduledTimer(timeInterval: 4.0, target: self, selector: #selector(catScan), userInfo: nil, repeats: false)

    catScanImage.animationImages = [
    UIImage(named: "catPerc0.png")!,
    UIImage(named: "catPerc1.png")!,
    UIImage(named: "catPerc2.png")!,
    UIImage(named: "catPerc3.png")!,
    UIImage(named: "catPerc4.png")!
    ]

    catScanImage.animationDuration = 0.4
    catScanImage.startAnimating()
    // Do any additional setup after loading the view, typically from a nib.
}

func catScan() {
    self.performSegue(withIdentifier: "lastSegue", sender: self)
}
func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    if segue.identifier == "lastSegue" {
        let dvc = segue.destination as! VCResult
        dvc.newImage = browsingImage.image
    }
}

}

The above prepare for segue is trying to move it to the next VC, but it does not get that far, it errors on

    browsingImage.image = newImage

within VCQScan, it does not appear to be moving the image even though I can see it in the debugger on VCPhoto... Thanks for any help!!!! Hopefully this is enough info, if not let me know! Again, I am new to Swift and Xcode so there is a chance I am missing something really stupid...

Debugger output 2017-04-03 20:08:33.637110-0700 OatQuizApp[3314:1066322 [OatQuizApp.VCResult buttonPressed:]:unrecognized selector sent to instance 0x100b1fdb0 2017-04-03 20:08:33.638569-0700 OatQuizApp[3314:1066322] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[OatQuizApp.VCResult buttonPressed:]: unrecognized selector sent to instance 0x100b1fdb0' * First throw call stack: (0x18ca7efd8 0x18b4e0538 0x18ca85ef4 0x18ca82f4c 0x18c97ed2c 0x192be30ec 0x192be306c 0x192bcd5e0 0x192be2950 0x192be246c 0x192bdd804 0x192bae418 0x1933a7f64 0x1933a26c0 0x1933a2aec 0x18ca2d424 0x18ca2cd94 0x18ca2a9a0 0x18c95ad94 0x18e3c4074 0x192c13130 0x1000cf900 0x18b96959c) libc++abi.dylib: terminating with uncaught exception of type NSException

Community
  • 1
  • 1
Nick Inman
  • 11
  • 5

1 Answers1

0

I figured out the issue.. Everything was coded correctly, at least originally. I was not paying attention regarding the UIImageView, I did not have one on VCQScan, just added an outlet, which is why it was coming up as null. I for some reason was thinking that the UIImageView was just carrying the image... I think I was staring at it too long. Thanks for looking!

Nick Inman
  • 11
  • 5