在 xcode 5 中实例化ViewControllerWithIdentifier
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21247868/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
instantiateViewControllerWithIdentifier in xcode 5
提问by tombornal
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:
我正在 xcode 5 中处理故事板。我有一个导航控制器,并且正在尝试在我的故事板中建立到其他场景的过渡。我首先尝试使用:
- (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 2013which suggested using instantiateViewControllerWithIdentifier
这会让我进入黑屏。在 stackoverflow 上搜索我发现这篇文章来自 2013 年 2 月,建议使用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'
Storyboard () 不包含带有标识符“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 IDand I can only see that when I click on the Viewand not the ViewControlleritself. When I click on the ViewController, I don't see Restoration IDnor Storyboard ID
我尝试弄清楚如何查找/设置标识符并看到引用的帖子Storyboard ID,但是当我查看我的屏幕时,我只能看到Restoration ID并且只有当我点击View而不是它ViewController本身时才能看到。当我点击 时ViewController,我没有看到Restoration ID也没有Storyboard ID
Any help would be greatly appreciated!
任何帮助将不胜感激!
回答by andrewcbancroft
The Storyboard IDproperty can be found in the Identity Inspectorof the View Controller:
该Storyboard ID属性可以Identity Inspector在视图控制器的中找到:
- Open up your storyboard.
- Click on the black barunderneath the view you've designed to display your details.
- Make sure you have the
Identity Inspectoropen on the right. It's the third icon at the top when you have theUtilitiespane open. - The second section in the
Identity Inspectoris labeled "Identity". The first property listed isStoryboard ID. You can set the value of it to "MPDetailPageViewController".
- 打开你的故事板。
- 单击您设计用于显示详细信息的视图下方的黑条。
- 确保
Identity Inspector右侧有开口。当您Utilities打开窗格时,它是顶部的第三个图标。 - 中的第二部分
Identity Inspector标记为“身份”。列出的第一个属性是Storyboard ID。您可以将其值设置为“MPDetailPageViewController”。
EDIT: Added screen shot:

编辑:添加屏幕截图:


