- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
SubController *nextController = [[SubController alloc] init];
[self.navigationController pushViewController:nextController animated:YES];
[nextController release];
}
appdelegation:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
tabBarController = [[UITabBarController alloc] init];
tabBarController.navigationItem.title = @" News";
TableViewController *rtbfViewController = [[TableViewController alloc]
init];
rtbfViewController.tabBarItem.title = @"News";
InfoViewController *infoViewController = [[InfoViewController alloc]
initWithStyle:UITableViewStyleGrouped];
infoViewController.tabBarItem.title = @"Info";
tabBarController.viewControllers = [NSArray
arrayWithObjects:rtbfViewController,infoViewController,nil];
tabBarController.customizableViewControllers = [NSArray arrayWithObjects:nil];
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
}
答案 0 :(得分:1)
问题是,您没有UINavigationController
,因此self.navigationController
中的TableViewController
为零(因此会忽略发送到此属性的消息)。您应该在app delegate中修改代码,如下所示:
// [...] create tab bar view controller...
// create navigation controller with TableViewController instance as root view controller
TableViewController *rtbfViewController = [[TableViewController alloc] init];
rtbfViewController.tabBarItem.title = @"News";
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:rtbfViewController];
// [...] create other view controllers
// NOTE: add the navigation controller to the tab bar controller, rather than the TableViewController
tabBarController.viewControllers = [NSArray arrayWithObjects:navController,infoViewController,nil];
tabBarController.customizableViewControllers = [NSArray arrayWithObjects:nil];
不要忘记之后发布你的视图控制器:
[rtbfViewController release];
[navController release];
[infoViewController release];