Reputation: 1008
i have a TabBarController with 3 Views / Tabs...At one Tab i have an UITableView. Now i want if the user clicks on a cell switch to a detailview...i tried it already with this code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailViewController *nextController = [self.storyboard instantiateViewControllerWithIdentifier:@"detailView"];
[self.navigationController pushViewController:nextController animated:YES];
}
But it doen´s work...Any Ideas?!
Upvotes: 1
Views: 956
Reputation: 38239
If u want to use navigation controller do like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//for home tab.. u want to add navigation controller
YourTableViewController *objviewController = [[[YourTableViewController alloc] initWithNibName:@"YourTableViewController_iPhone" bundle:nil] autorelease];
UINavigationController *navCtrl = [[UINavigationController alloc] initRootViewController:objviewController];
//for tab2...
YourSecondViewController *objYourSecondViewController = [[[YourTableViewController alloc] initWithNibName:@"YourSecondViewController_iPhone" bundle:nil] autorelease];
//for tab3...
YourThirdViewController *objYourThirdViewController = [[[YourThirdViewController alloc] initWithNibName:@"YourThirdViewController_iPhone" bundle:nil] autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navCtrl,objYourSecondViewController,objYourThirdViewController,nil];
self.window.rootViewController=self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
But u can add also add like if don't need navigation controller:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailViewController *nextController = [self.storyboard instantiateViewControllerWithIdentifier:@"detailView"];
[self.view addSubView:nextController];
}
Upvotes: 0
Reputation: 17732
You need to embed the table view controller in a navigation controller
Upvotes: 1