Reputation:
hai , i have coded in UITableview in the method as follows.but when i touch the cell or row ,it wont go to the next page(navigation did not work).have i to declare navigation conroller in other file.but i have coded app delegate in applicationdidfinishmethod for tab bar through dynamic.how can i link navigation? the code: UITableview;(TableViewController)
- (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];
}
Upvotes: 0
Views: 604
Reputation: 8855
The problem is, that you don't have a UINavigationController
, so self.navigationController
in your TableViewController
is nil (and thus messages sent to this property are ignored). You should modify your code in the app delegate as follows:
// [...] 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];
And don't forget to release your view controllers afterwards:
[rtbfViewController release];
[navController release];
[infoViewController release];
Upvotes: 1