4 Replies Latest reply: Jun 17, 2012 12:04 PM by Llessur999
TechGeniusApps Level 1 Level 1 (0 points)

I have been researching on how to add UINavigationController (I've been using UINavigationBars since) but all of them include putting the UINavigationController code in the App Delegate. The problem here is that only 2 view (root and detail) are the only ones that use UINavigationController and UITableViews. All my other views (10 so far, more to come) use modal transitions. So creating a UINavigationController in the appdelegate would be useless. How can I add a UINavigationController only in the .h & .m? And then push a detail view controller from a row (Only the top row, but I already have to code working on checking if the user taps on the first row. Right now when the user taps o the first row, it shows the next view in a modal tradition, but I want to replace it with push, but I know my current code works)? Also, the current view I want to be root contains (currently) a UINavigationBar with a done button (left side) and a custom bordered button (on the right), a UITableView, and a UIToolbar with 2 custom buttons and 3 flexible spaces. I need all of these shown (UInavigationBar will be replaced by UINavigationController and the done button needs to show only on the root view and get replaced by back button on the detail, and custom buton needs to remain there on both views.) Pushing view controllers and UINavigationControllers are new to me, I'm trying to grasp it.

 

Message was edited by: TechGeniusApps


MacBook Pro, Mac OS X (10.7.4), 17 inch, Intel i7 Dual Core Mid2010
  • TechGeniusApps Level 1 Level 1 (0 points)

    Pictures:

    Root view

    Detail View

     

    Edited: Click on picture to open bigger picture

  • Llessur999 Level 4 Level 4 (1,190 points)

    TechGeniusApps wrote:

     

    ...but all of them include putting the UINavigationController code in the App Delegate. The problem here is that only 2 view (root and detail) are the only ones that use UINavigationController and UITableViews. All my other views (10 so far, more to come) use modal transitions. So creating a UINavigationController in the appdelegate would be useless...

     

    If the root view uses a UINavigationController, can't you just use modal segues from the root view controller for the 10 modal views?  You can still have your own UIBarButtons on the master view, just add them to the UINavigationItem in the storyboard.

     

    I assume you are using a storyboard. Look at the the Master-Detail Application project template, the storyboard starts with a UINavigationController, and no code in AppDelegate is required.

     

    I this misses the point of your question, I suggest you clearly describe what you are trying to accomplish and what problem you have encountered.

  • TechGeniusApps Level 1 Level 1 (0 points)

    First of all, I am not using storyboard. What I am trying to do is the root view controller is not the first view shown in the app. How and where would I setup the navigation controller?

  • Llessur999 Level 4 Level 4 (1,190 points)

    Just create the the UINavigationController wherever you need to show its root view controller. With no storyboard segue you would typically use something like this. I initiated from a UIButton action for this example. Instead of a generic UITableViewController, use the custom view controller class of your root view controller (PauseMenuTableViewController?). If you are using old-school nib/xib, replace initWithStyle with initWithNibName.

     

    - (IBAction)showWhateverViewButtonClick:(id)sender {

        // create whatever view controller type will be the root of the navigation controller

        UIViewController *rootViewController = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];

       

        // create a navigation controller using that view controller for the root

        UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];

       

        // show the navigation controller (modal)

        [self presentViewController:navigationController animated:YES completion:NULL];

    }