以编程方式移动到其他视图会导致黑屏

时间:2014-03-24 18:04:28

标签: ios objective-c xcode5

我正在使用此代码以编程方式从我的主屏幕(登录页面)移动到其后面的视图,但它会显示黑屏;

LandingController *landingController = [[LandingController alloc] init];
[self presentViewController:landingController animated:YES completion:nil];

我已将LandingController.h文件包含在我的ViewController.h中,并且也没有出现任何错误。

当我从上面代码中的LandingController(未提及)中删除我的Storyboard ID时,收到此消息:

/Users/allendar/Desktop/iOS Apps/#HIDDEN# App/#HIDDEN# App/Base.lproj/Main_iPad.storyboard: Scene is unreachable due to lack of entry points and does not have an identifier for runtime access via -instantiateViewControllerWithIdentifier:.

我假设这有事做,我只为View调用相关的Controller,而它实际上并没有实例化View的内部。

我已经通过触发LandingController的故事板ID尝试了其他一些示例,但它会出错或者什么都不做(就像这段代码一样)。

任何想法如何在触发Controller时调用View本身,或者通过Storyboard ID进行调用?

2 个答案:

答案 0 :(得分:1)

试试这个:

    UIStoryboard *storybboard = [UIStoryboard storyboardWithName:@"YOURSTORYBOARD" bundle:nil];
LandingController * landingController  = [storybboard instantiateViewControllerWithIdentifier:@"STORYBOARD ID"];
[self presentViewController: landingController animated:YES completion:nil];

答案 1 :(得分:1)

尝试从故事板加载视图控制器,而不是使用alloc-> init。为您的视图控制器提供故事板中的标识符,并按如下方式加载:

[self presentViewController:[[UIStoryboard storyboardWithName:@"YourStoryBoardName" bundle:nil] instantiateViewControllerWithIdentifier:@"YourIdentifier"]];