简体   繁体   中英

How to navigate to another UIView controller (previously created in storyboard) by pressing an image

I have created an image in my current story board and then I added the tap gesture to it so now once it's been tapped I know . Then I've created an other UIView controller in my story board which is connected to the cocatoch class called "DetailedUIViewController.swift" . Now I want to move to that view once I clicked on my image .

Here is my image :

@IBOutlet weak var totalEnergy: UIImageView!

and here is my tap gesture definition :

    let TGTE = UITapGestureRecognizer(target: self, action: #selector(totalEnergyFunc))
    totalEnergy.isUserInteractionEnabled = true
    TGTE.numberOfTapsRequired = 1
    totalEnergy.addGestureRecognizer(TGTE)

and here is the function that get called once I click on the image :

   func totalEnergyFunc(){

}

Now what I am trying to get is how to move to the second view which is previously created once my function get called ?

Make sure you have a storyboard ID for DetailedUIViewController

Press Command + Option + 3 and set storyboard ID for DetailedUIViewController

故事板ID

Present DetailedUIViewController in totalEnergyFunc method

func totalEnergyFunc(){
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "someViewController")
self.present(controller, 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