minjiera
minjiera

Reputation: 336

instantiateViewControllerWithIdentifier show blank view (xcode 4.5)

I heard that in XCode 4.5 there's some changes that the Storyboard identifier is no longer called identifier but Storyboard ID. I tried to use it but it doesn't initiate anything. It's always blank. What am I doing wrong?

 UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];

 HistoryViewController* historyVC = [storyboard instantiateViewControllerWithIdentifier:@"histSB"];

With

  [self presentViewController:historyVC animated:YES completion:nil];

OR

 [self.navigationController pushViewController:historyVC animated:YES];

OR

 [self presentModalViewController:historyVC animated:YES];

See screenshot for settings in storyboard:

enter image description here

Upvotes: 3

Views: 8178

Answers (1)

mpemburn
mpemburn

Reputation: 2884

This is something I use a few times in my app for those places were segues are impractical. Going from the code and screen shot provided above, here's how I'd wire it up:

HistoryViewController *historyVC = [self.storyboard instantiateViewControllerWithIdentifier: @"histSB"];
[self.navigationController pushViewController: historyVC animated:YES];

This is particularly useful if you're displaying your view controller from a popopver on iPad. Add the view with its own navigation controller to the storyboard:

enter image description here

Notice that there's no segue coming in to the left side of the navigation controller. The following code displays this in the popover:

HistoryViewController *historyVC = [self.storyboard instantiateViewControllerWithIdentifier: @"histSB"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController: historyVC];
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController: navigationController];

You can then use this as a basis for pushing other view controllers onto the navigation controller via a segue (notice the one to the right side of the view controller):

[self performSegueWithIdentifier: @"WhateverComesNextSegue" sender: self];

Hope that helps.

Upvotes: 3

Related Questions