在appDelegate中访问故事板和嵌套的UIViewControllers

时间:2014-02-04 15:56:19

标签: ios objective-c xcode5 uistoryboard

如何访问storyboard以及appDelegate中的UIViewControllers。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    return YES;
}

2 个答案:

答案 0 :(得分:1)

试试这个:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *uvc = [storyboard instantiateViewControllerWithIdentifier:@"Details"];
[self.window.rootViewController presentViewController:uvc animated:YES completion:nil];

答案 1 :(得分:0)

对于你的UIViewController名为MyViewController并且其storyboard名称为MyViewController.storyboard的情况,你请求的代码如下所示:

// load storybord with name MyViewController.storyboard
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MyViewController" bundle:nil];

// get an instance of root view controller for the storyboard
MyViewController *viewController = [storyboard instantiateInitialViewController];