iOS Application tried to push a nil view controller on target

项目当中遇到过这种问题
控制台提示
Application tried to push a nil view controller on target .(试图推出空的试图控制器)

先说下项目的情况,
由于我要push 的控制器是用StoryBoard画的,
而我自己新建的rootVIewController 用代码所编写,

那么,在push的时候 显然用不了StoryBoard直接连线的方法,

这里,自己push过去 就会提示找不到所要push的控制器资源,

解决方法:

//Main 是storyboar的资源名
_storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
//实例化一个所要push的控制器
PerfectInformationViewController *informationVC = [_storyBoard instantiateViewControllerWithIdentifier:@"informationVC"];
//这样,就让资源链接起来了


1.原因:
采用self.storyboard时,获得的storyboard对象为空

2.修改方法:
初始化一个storyboard对象,然后使用这个对象获得相应的viewcontroller;

3.代码演示:

UIStoryboard *stroyboard = [UIStoryboard storyboardWithName:@"Setting" bundle:nil];
PerfectPersonalInfoViewController *infoVC = [stroyboard instantiateViewControllerWithIdentifier:@"PerfectPersonalInfoVCStoryBoardID"];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:infoVC];
infoVC.info = data;
infoVC.detail = wechatinfo;
[self presentViewController:nav animated:YES completion:nil];

你可能感兴趣的:(iOS Application tried to push a nil view controller on target)