简体   繁体   中英

How to open next viewcontroller after choosing image from gallery (swift)

I am trying to open next viewController after choosing photo from gallery. I can get image from gallery, but after that I dont know how to open controller next to it. !. This is photo of that storyboard

You can put an UITapGestureRecognizer inside your UIImageView using Interface Builder or in code (as you want), I prefer the first. The you can put an @IBAction and handle the tap inside your UIImageView , Don't forget to set the UserInteractionEnabled to true in Interface Builder or in code.

To present the next view controller you can do it in code like below or just using Interface Builder using a segue through the UITapGestureRecognizer you set before (it's up to you).

To present the view controller manually like in the following code you need to set the Storyboard ID for you view controller like in the following picture (in the Identity Inspector panel ):

在此处输入图片说明

@IBAction func imageTapped(sender: AnyObject) {

    // Set the storyboard name by default is Main
    let storyboard = UIStoryboard(name: "MyStoryboardName", bundle: nil)

    // Instantiate the ViewController with the name you set before like in the image
    let nextViewController = storyboard.instantiateViewControllerWithIdentifier("ViewControllerB") as! UIViewController

    // present the nextViewController
    self.presentViewController(nextViewController, animated: true, completion: nil)
}

I hope this help you.

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