Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a navigation controller to a view-based application?

Is it possible to add a UINavigationController to a view application that inherits from UIViewController and not UITableViewController? How is it done?

like image 237
node ninja Avatar asked Sep 20 '10 11:09

node ninja


People also ask

How do I get navigation controller root view controller?

The root view controller is simply the view controller that sits at the bottom of the navigation stack. You can access the navigation controller's array of view controllers through its viewControllers property. To access the root view controller, we ask for the first item of the array of view controllers.

How do I add a navigation bar to a table view controller?

Show activity on this post. From the outline view, make sure your Table View Controller is selected. Then go to the Editor menu, and click on the Embed In submenu, and choose Navigation Controller and voila. You have your navigation controller pointing to your tableview controller with a relationship built in.


1 Answers

Yes, you can have Navigation controllers in any view based application, whether at the Root level (like when you create the Navigation-based template in Xcode) or with a TabBar root, or with any Root.

One example, presenting a modal view including navigation (used in my app to display a series of forms):

    UIViewController *control = [[MyViewController alloc] initWithNibName: @"MyViewController" bundle: nil];
    UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController: control];
    [self presentModalViewController: navControl animated: YES];
    [control release];

In another example, if you want to have it at the root level, but didn't create the application with the Navigation template, in the AppDelegate's didFinishLaunching(...):

    UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController: control];
    [window setRootViewController: navControl];
    [navControl release];

You can also set it in Interface Builder, by setting up the class of the View controller you use (UIViewController replaced by UINavigationController).

I hope this answers your question (sorry about the previous discussion).

like image 177
jv42 Avatar answered Sep 28 '22 06:09

jv42