听说在XCode 4.5中有一些变化,Storyboard identifier不再叫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中设置的屏幕截图:
最佳答案
这是我在我的应用程序中使用过几次的东西,用于那些 segues 不切实际的地方。根据上面提供的代码和屏幕截图,以下是我的连接方式:
HistoryViewController *historyVC = [self.storyboard instantiateViewControllerWithIdentifier: @"histSB"];
[self.navigationController pushViewController: historyVC animated:YES];
如果您从 iPad 上的弹出窗口显示 View Controller ,这将特别有用。将带有自己的导航 Controller 的 View 添加到 Storyboard:
请注意,导航 Controller 左侧没有 segue。以下代码在弹出窗口中显示此内容:
HistoryViewController *historyVC = [self.storyboard instantiateViewControllerWithIdentifier: @"histSB"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController: historyVC];
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController: navigationController];
然后,您可以以此为基础,通过 segue(注意 View Controller 右侧的那个)将其他 View Controller 推送到导航 Controller 上:
[self performSegueWithIdentifier: @"WhateverComesNextSegue" sender: self];
希望对您有所帮助。
关于iphone - instantiateViewControllerWithIdentifier 显示空白 View (xcode 4.5),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12843815/