Saturday, 17 October 2015

IOS: Perform the segue programmatically

      In most of your ios apps you will be having more than one window and will also have cases that you want to switch from your current viewController to another viewController. you could achieve it by just ctrl+dragging from your button in first viewController to second view control and selecting 'show' option from the popup menu.

      But their are cases when you want to segue from one to another programatically without a button click. In such cases you will have to ctrl+drag from the first viewController to second viewController and select 'show' option from the popup menu and set an identifier for the newly added segue. And now you have to copy past the below code to your programe where you want to perform the segue programmatically. Dont forget to replace the identifier in the sample code with your segue identifier or else the app will crash.

Swift:
 self.performSegueWithIdentifier("<Segue_Identifier>" ,sender: self)  

If it doesn't work then try:
 self.shouldPerformSegueWithIdentifier("<Segue_Identifier>" ,sender: self)  

Its really cool with swift isn't it!


No comments:

Post a Comment