Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a UINavigationBar to a UITableViewController without a UINavigationController

I have an existing UITableViewController that was previously being used in a UINavigationController.

I need to convert it to be presented as a modal view. However, I still want to have a navigation bar at the top. I know this sounds strange- why not present it in the UINavigationController if I want a UINavBar? I want to present it without the UITabBarController that is associated with my UINavigationController.

I tried opening the XIB, adding a new view, moving the UITableView to be a subview and adding a NavigationBar to that new view as well. However this doesn't seem to make any impact and the whole tableview is still presented - no nav bar is visible. I think this is because the class is a subclass of UITableViewController.

Do I need to convert this to a UIViewClass? Is there a good approach to adding a navbar in code or via Interface Builder to an existing UITableViewController?

Thanks for any advice on how to approach this.

like image 300
Nick Avatar asked Oct 27 '10 16:10

Nick


1 Answers

Did you change the connection in the XIB for the File's Owner view? It should point to your outer view which contains both the navbar and tableview.

But I'm not sure I understand why you don't want to use a navigation controller. Just do this:

MyViewController *viewController = [[[MyViewController alloc] init] autorelease];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:viewController] autorelease];
[self presentModalViewController:navController animated:YES];

I do this all the time when presenting a modal view - it seems cleaner than including a navbar directly in the view.

like image 97
Brian Avatar answered Nov 12 '22 16:11

Brian