How to add multiple segues from one viewController

Multi tool use
Multi tool use


How to add multiple segues from one viewController



I have a UI view controller(viewControllerOne) with a table view in it. I have a segue from a button in the cell to another viewController (viewControllerTwo).



This works fine.
now , i have a third view controller and want to have a segue from another button in View Controller one .
How to have multiple segues from one view controller to go to different viewController.




2 Answers
2



First segue should be between the VC itself ( not a button inside the cell ) to the destinationVC as to be able to send data in prepareforSegue , so from the yellow icon of VC1 drag to both VC2 and VC3 and give a segue identifier like toSecond & toThird respectively then in code do


prepareforSegue


// change segue identifier if you want to third
self.performSegue(withIdentifier: "toSecond ", sender:nil)





After that I used if else statements in prepare for segue and it worked fine. 👍
– user00007
Jul 1 at 6:47




Segues inside UITableViewCell should be done programmatically. Use the didSelectCell at indexPath method. When this is called, you should perform a segue based on the indexPath. I personally recommend having an array of structs to keep track of the UITableViewCells. For example:


UITableViewCell


didSelectCell at indexPath


UITableViewCells


struct tableViewCell {
var cell: UITableViewCell
var segue: String
}

var cells: Array<Array<tableViewCell>> = ;

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: IndexPath) {
self.performSegue(withIdentifier: cells[indexPath.section][indexPath.row].segue);
}



Sorry if there are any typos, this code was not written in xcode.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

GCpQIwPwq16PUm57DqEl,Xiit 2BnM,q X,qBl1Vm KWP
hW fUQxZ0YazU2ZMHK3p5 vMPlego o2ALvf4ZCX4R2Ce5,hlXSKGLe,IhVdTm8akw9

Popular posts from this blog

PySpark - SparkContext: Error initializing SparkContext File does not exist

django NoReverseMatch Exception

List of Kim Possible characters