在这种情况下,您可以从 Storyboard 实例中实例化 UIViewController 实例:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"YourStoryboard" bundle:nil];
UIViewController *newController = [storyboard instantiateInitialViewController];
这假设您将从该 StoryBoard 实例中的初始视图控制器开始。
您可以将此与条件配对以执行以下操作:
UIViewController *newViewController = nil;
if([self databaseHasNewInformation])
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"NewDataStoryboard" bundle:nil];
newController = [storyboard instantiateInitialViewController];
}
else
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"NoNewDataStoryboard" bundle:nil];
newController = [storyboard instantiateInitialViewController];
}
// Present New View Controller (this example assumes a navigation controller)
[self.navigationController pushViewController:newController animated:YES];
如果您想实例化一个不是 StoryBoard 中初始视图控制器的视图控制器,您可以考虑利用另一个实例 -(id)instantiateViewControllerWithIdentifier:(NSString *)identifier
而不是调用instantiateInitialViewController