在 Swift 中关闭 UIImagePickerController 后如何切换到另一个视图?

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

我正在尝试拍照,调整照片大小,然后点击 "Use Photo" 并切换到同时显示原始图像和编辑后图像的新视图。我的问题是在点击 "Use Photo" 后显示新视图。使用我当前的代码,我可以很好地关闭 ImagePickerController,但它会返回到主视图,然后我会看到黑屏。

    @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)

    }

我的 decisionController View 在一个单独的 swift 文件中,它在我的故事板中。它将 class 设置为 decisionController。我通常会在我的下一个视图中创建一个 segue,但是我没有可以引用的按钮,因为我使用的是通用 UIImagePickerController。

这是我的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.
    }
}

如果您想在不使用 segue 的情况下从情节提要中加载场景,可以通过将情节提要 ID 添加到情节提要中的场景,然后在情节提要中调用 instantiateViewControllerForIdentifier: 来实现。

假设呈现的视图控制器在同一个故事板中,通过在故事板中选择视图控制器并在身份检查器中的故事板 ID 下填写一个值(命令-选项-3).

替换:

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

与:

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