TabBarController + TableView with DetailViews
i have created a TabBar Application. I Added to a view an UITableView and load some Data inside.
Now开发者_StackOverflow中文版, i wont to show details on row click. So i read some articles and found out that i need a navigationController und so on, but where to insert it? Should i delete my UITableView?
Just drag a UINavigationController in Interface Builder to your TabBarController, then expand the Navigation Controller, point the Root View Controller to your TableViewController.
This tutorial should help: http://blog.willwinder.com/2011/05/xcode4-uitabbarcontroller-with.html
No you should not delete your UITableView, what you want is UITableViewController that can use your UITableView.
You will need the UINavigationController when you want to show another ViewController when the user taps a row on your UITableViewController.
This tutorial explains how to do what I just described, hope it helps:
Table View and NavigationController
Just add an UINavigationController and push the view onto your screen
EDIT: This is how to add the NavigationController programmatically (e.g. in you AppDeleagte)
UIViewController *viewController1, *viewController2;
viewController1 = [[[UIViewController alloc] initWithNibName:@"FirstViewController_iPhone" bundle:nil] autorelease];
UINavigationController *navigationcontroller = [[[UINavigationController alloc] initWithRootViewController:viewController1] autorelease];
viewController2 = [[[UIViewController alloc] initWithNibName:@"SecondViewController_iPhone" bundle:nil] autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navigationcontroller, viewController2, nil];
If you have a tableview in the Viewcontroller1 you can access the Navigationcontroller by using self.navigationController
e.g. in the didSelectRowAtIndexPath
to open a DetailView
eg.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
精彩评论