【发布时间】:2011-12-05 23:11:13
【问题描述】:
我的导航控制器无法正常运行!如果我在 RootViewController 处单击表格的单元格,它不会显示为下一个 ViewController。
错误信息读取
“应用程序试图在目标上推送一个 nil 视图控制器 。”
所以我分配了一些错误的东西,这是我的猜测,我可能错过了我所遵循的书中的一些重要内容。
所以问题出现在我的 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;
}
所以当我单击单元格时,我得到了我想要推送的所有其他 ViewController。我就是看不到我的错或我错过了什么!?
也许有人可以帮助我并给我一个提示!那太好了!
【问题讨论】:
-
kundeViewCon、kalenderViewCon 和 wunschViewCon 是在哪里创建的?
-
这都是独立的类,它们是在 RootViewController.h 中创建的
-
我无法设置 (at),因为我用它命名用户,所以 (at) 是存在的!class KundeViewController;类 KalenderViewController;类 WunschViewController;接口 RootViewController : UITableViewController
{ KundeViewController *kundeViewCon; KalenderViewController *kalenderViewCon; WunschViewController *wunschViewCon; } 结束
标签: ios uinavigationcontroller didselectrowatindexpath