Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
794 views
in Technique[技术] by (71.8m points)

ios - instantiateViewControllerWithIdentifier in xcode 5

I'm working on a storyboard in xcode 5. I have a navigation controller, and am trying to establish the transitions to other scenes in my storyboard. I first tried using:

- (IBAction)handleTap:(UITapGestureRecognizer *)sender {
NSLog(@"Image clicked");

_detailPage = [[MPDetailPageViewController alloc] initWithNibName:@"MPDetailPageViewController" bundle:nil];
_detailPage.product = _curProduct;

//Bring to detail page
[self.navigationController pushViewController:self.detailPage animated:YES];
}

This would bring me to a black screen. Searching on stackoverflow I found this post from Feb 2013 which suggested using instantiateViewControllerWithIdentifier

So I tried:

- (IBAction)handleTap:(UITapGestureRecognizer *)sender {
NSLog(@"Image clicked");

_detailPage = [self.storyboard instantiateViewControllerWithIdentifier:@"MPDetailPageViewController"];
_detailPage.product = _curProduct;

//Bring to detail page
[self.navigationController pushViewController:self.detailPage animated:YES];
}

However, this gave me an error

Storyboard () doesn't contain a view controller with identifier 'MPDetailPageViewController'

I tried figuring out how to find/ set the identifier and saw posts referencing Storyboard ID, but when I look on my screen I only see Restoration ID and I can only see that when I click on the View and not the ViewController itself. When I click on the ViewController, I don't see Restoration ID nor Storyboard ID

Any help would be greatly appreciated!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The Storyboard ID property can be found in the Identity Inspector of the View Controller:

  1. Open up your storyboard.
  2. Click on the black bar underneath the view you've designed to display your details.
  3. Make sure you have the Identity Inspector open on the right. It's the third icon at the top when you have the Utilities pane open.
  4. The second section in the Identity Inspector is labeled "Identity". The first property listed is Storyboard ID. You can set the value of it to "MPDetailPageViewController".

EDIT: Added screen shot: enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...