項(xiàng)目當(dāng)中遇到過這種問題
控制臺(tái)提示
Application tried to push a nil view controller on target .(試圖推出空的試圖控制器)
先說下項(xiàng)目的情況,
由于我要push 的控制器是用StoryBoard畫的,
而我自己新建的rootVIewController 用代碼所編寫,
那么,在push的時(shí)候 顯然用不了StoryBoard直接連線的方法,
這里,自己push過去 就會(huì)提示找不到所要push的控制器資源,
解決方法:
//Main 是storyboar的資源名
_storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
//實(shí)例化一個(gè)所要push的控制器
PerfectInformationViewController *informationVC = [_storyBoard instantiateViewControllerWithIdentifier:@"informationVC"];
//這樣,就讓資源鏈接起來了
1.原因:
采用self.storyboard時(shí),獲得的storyboard對(duì)象為空
2.修改方法:
初始化一個(gè)storyboard對(duì)象,然后使用這個(gè)對(duì)象獲得相應(yīng)的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];