简体   繁体   中英

How do switch to another view after dismissing UIImagePickerController in Swift?

I am trying to take a photo, resize it and then tap "Use Photo" and switch over to a new view that displays both, the original image and edited image. My trouble is having the new view display after tapping "Use Photo". With my current code, I can dismiss the ImagePickerController just fine but then it goes back to the main view and then I get a black screen.

    @IBAction func pickerButton(button: UIButton)
{
    var controller : UIImagePickerController = UIImagePickerController();
    controller.delegate = self
    //controller.allowsEditing = true
    self.presentViewController(controller, animated: true, completion: nil)

}    

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject])
{
    var mediaDictionary : NSDictionary = info as NSDictionary

    println("here it comes")

    var pickerMedia : String = mediaDictionary.objectForKey("UIImagePickerControllerMediaType") as! String
    dump(pickerMedia)

    if (pickerMedia == "public.image"){
        ///////Loading dictionaries for value pairs that don't exist as of video capture video
        var anImage : UIImage = mediaDictionary.objectForKey("UIImagePickerControllerOriginalImage") as! UIImage

        /////////Optional for edited image
        var editedImage : UIImage = mediaDictionary.objectForKey("UIImagePickerControllerEditedImage") as! UIImage

    // Dismiss the image picker         
    picker.dismissViewControllerAnimated(true, completion: nil)
    // Here is my issue...
    var svc : decisionController = decisionController()
    self.presentViewController(svc, animated: true, completion: nil)

    }

My decisionController View is in a separate swift file and it is in my storyboard. It has the class set to decisionController. I would normally create a segue into my next view but I don't have a button to reference to since Im using a generic UIImagePickerController.

Here is my decisionController.swift

import UIKit

class decisionController: UIViewController {

    @IBOutlet var anImageView : UIImageView?
    @IBOutlet var anotherImageView : UIImageView?

    override func viewDidLoad() {

        super.viewDidLoad()

        //anImageView!.image = anImage
        //anotherImageView!.image = editedImage

        // Do any additional setup after loading the view, typically from a nib.
    }
}

If you want to load a scene from your storyboard without using a segue, you can do so by adding a Storyboard ID to the scene in the storyboard and then invoking instantiateViewControllerForIdentifier: on the storyboard.

Assuming that the presenting view controller is in the same storyboard, this code should work after you set the Storyboard ID by selecting the view controller in the storyboard, and filling in a value under Storyboard ID in the identity inspector (command-option-3).

Replace:

// Here is my issue...
var svc : decisionController = decisionController()
self.presentViewController(svc, animated: true, completion: nil)

with:

let svc = self.storyboard!.instantiateViewControllerWithIdentifier("decisionControllerStoryboardID") as! decisionController
self.presentViewController(svc, animated: true, completion: nil)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM