实例化具有标识符的视图控制器显示空白视图(Xcode 4.5)

3

我听说在XCode 4.5中有些变化,Storyboard的标识符不再称为identifier而是Storyboard ID。我试着使用它,但它没有进行任何初始化,总是空白的。我做错了什么?

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

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

随着

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

或者

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

或者

 [self presentModalViewController:historyVC animated:YES];

请看Storyboard中的设置截图:

enter image description here


所以除了标准的“MainStoryboard.storyboard”之外,您还有一个名为“Storyboard.storyboard”的第二个故事板文件? - ilmiacs
所以我只有一个...而且那就是我给它起的名字。(那是在我意识到有一种命名惯例之前。但除此之外,故事板加载得很好。) - minjiera
如果您只有一个,则父VC定义在同一SB中。在这种情况下,您可以使用self.storyboard,我经常使用它而没有问题。如果这也不起作用,那么可能与您的VC实现有关。 - ilmiacs
1个回答

3

在我的应用程序中,我会在那些不适合使用转场的地方使用以下方法。从上面提供的代码和截图中,这是我如何连接它的:

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

如果您正在iPad上从一个弹出菜单中显示您的视图控制器,这将特别有用。在故事板中添加带有自己导航控制器的视图:

enter image description here

注意,导航控制器的左侧没有segue。以下代码在弹出窗口中显示它:

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

您可以将此作为基础,通过segue(注意view controller右侧的那个)将其他view controller推到导航控制器上:

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

希望这有所帮助。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接