Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Present storyboard ViewController from another ViewController

Tags:

I have multiple UIViewControllers in my iOS App's Storyboard. I want to open one of the UIViewControllers (in the storyboard) from a different UIViewController.

I've tried the code below, but it isn't working even though I used it before iOS 5 and it worked fine.

- (IBAction)addNotes:(id)sender {     NotesViewController *notesView = [[NotesViewController alloc] initWithNibName:@"NotesViewController" bundle:nil];     [self presentModalViewController:notesView animated:YES]; } 

How can I perform this action with iOS 5 Storyboards?

like image 930
Ranjit Avatar asked Jan 19 '12 09:01

Ranjit


People also ask

How do I present a view controller from another view controller?

You may also start segues from table rows and collection view cells. Right-click the control or object in your current view controller. Drag the cursor to the view controller you want to present. Select the kind of segue you want from the list that Xcode provides.


1 Answers

Assuming you have storyboard, go to storyboard and give your VC an identifier (inspector), then do:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"IDENTIFIER"]; [self.navigationController pushViewController:vc animated:YES]; 

Assuming you have a xib file you want to do:

UIViewController *vc = [[UIViewController alloc] initWithNibName:@"NIBNAME" bundle:nil]; [self.navigationController pushViewController:vc animated:YES]; 

Without a xib file:

UIViewController *vc = [[UIViewController alloc] init]; [self.navigationController pushViewController:vc animated:YES]; 
like image 101
DAS Avatar answered Nov 30 '22 00:11

DAS