ObjC - presentViewController中断

时间:2015-02-24 09:14:24

标签: objective-c xcode show viewcontroller

我正在尝试以编程方式显示另一个View Controller。我写了一些我从示例中学到的代码,它没有给出任何错误。但它打破并以绿色显示:

return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); thread 1 : signal SIGABRT

我使用了这段代码:

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"secondViewController"];
    [self presentViewController:vc animated:NO completion:nil];

我的代码有问题,还是别的?

提前致谢。

1 个答案:

答案 0 :(得分:0)

这可能是因为您的故事板中没有带有故事板ID secondViewController UIViewController

您可以将UIViewcontroller拖到Storyboard,并在Identity检查器中将Storyboard ID拖到 secondViewController 。 见下图

enter image description here

我希望这会有所帮助:)