xcode 5中的instantiateViewControllerWithIdentifier

时间:2014-01-21 02:12:31

标签: ios iphone objective-c xcode xcode5

我正在使用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];
}

这会让我陷入黑屏。在stackoverflow上搜索,我发现this post from Feb 2013建议使用instantiateViewControllerWithIdentifier

所以我试过了:

- (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];
}

然而,这给了我一个错误

  

Storyboard()不包含标识符为“MPDetailPageViewController”的视图控制器

我尝试了解如何查找/设置标识符并看到引用Storyboard ID的帖子,但当我在屏幕上看时,我只看到Restoration ID,我只能看到当我点击View而不是ViewController本身。当我点击ViewController时,我看不到Restoration IDStoryboard ID

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:17)

Storyboard ID属性可以在View Controller的Identity Inspector中找到:

  1. 打开你的故事板。
  2. 点击您设计用于显示详细信息的视图下方的黑条
  3. 确保右侧打开Identity Inspector。当您打开Utilities窗格时,它是顶部的第三个图标。
  4. Identity Inspector中的第二部分标有" Identity"。列出的第一个属性是Storyboard ID。您可以将其值设置为" MPDetailPageViewController"。
  5. 编辑:添加了屏幕截图: enter image description here