我有问题让我的导航控制器正常运行!如果我在RootViewController中单击表格的单元格,它似乎不是下一个ViewController. 错误消息读取 “Application tried to push a nil view controller on target .” 所以我
错误消息读取
“Application tried to push a nil view controller on target
.”
所以我分配了一些错误的东西,我的猜测,我可能遗漏了我所遵循的书中的重要内容.
所以问题出现在我的RootViewController.m中:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UINavigationController *navigationController= [[UINavigationController alloc]init];
switch ([indexPath row]) {
case 0:
[navigationController pushViewController:kundeViewCon animated:YES];
break;
case 1:
[navigationController pushViewController:kalenderViewCon animated:YES];
break;
case 2:
[navigationController pushViewController:wunschViewCon animated:YES];
break;
}
}
在我的AppDelegate.m中,我正在做以下事情来设置RootViewController作为NavigationController:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
// Navigation Controller
RootViewController *rootViewController = [[RootViewController alloc]init];
navigationController = [[UINavigationController alloc]initWithRootViewController:rootViewController];
self.window.backgroundColor = [UIColor whiteColor];
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
所以当我点击Cell时,我得到了我想要推送的所有其他ViewControllers.我只是看不出自己的错或我错过了什么!?
也许有人可以帮助我并给我一个提示!那太好了!
RootViewController已经有了它的导航控制器 – 你在app delegate中创建了它.选择单元格时创建新的导航控制器没有意义.它应该看起来更像这样:- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
switch ([indexPath row]) {
case 0:
[self.navigationController pushViewController:kundeViewCon animated:YES];
break;
case 1:
[self.navigationController pushViewController:kalenderViewCon animated:YES];
break;
case 2:
[self.navigationController pushViewController:wunschViewCon animated:YES];
break;
}
}
另外,只需确保在调用-pushViewController:animated时:视图控制器(即kundleViewCon,kalenderViewCon& wunschViewCon)是非零的.它们看起来像实例变量或属性 – 只需确保在代码中早先分配/启动它们,例如在-viewDidLoad中.
