There are instances when you want to transition or navigate from one UI screen to other by press of button.
Yes you can link button visually by control clicking on button & then linking that button to required UI Screen on storyboard.
But I will show you how you can do it programatically with code defined & working differently for iPad & iPhone Storyboards.
I have used iOS Conditional coding syntax for differentiate iPhone & iPad Storyboards
Step 01: Use following code for your choice of UI Button IBAction Sender button
- (IBAction)exitButton:(id)sender { if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { UIViewController *obj = [[UIStoryboard storyboardWithName:@"Main_iPad" bundle:nil] instantiateViewControllerWithIdentifier:@"ViewController"]; [self.navigationController pushViewController:obj animated:YES]; } else { UIViewController *obj = [[UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil] instantiateViewControllerWithIdentifier:@"ViewController"]; [self.navigationController pushViewController:obj animated:YES]; } }
Step 02: Now navigae to Storyboard right hand panel for ‘Storyboard ID Property’ which can be can be found in the Identity Inspector of the View Controller:
- Open up your storyboard in your Xcode project
- Make sure you have the Identity Inspector open on the right side panel i.e. Third icon at the top when you have the Utilities pane open
- The second section in the Identity Inspector is labeled “Identity”, The first property listed is Storyboard ID, You have to set the value of it to “ViewController”
Now you are good to go,
Try to run your app in simulator or on your device to check if it is working or not.
Hope it helps,
Thanks & Regards
Mandar Apte