Swapping out root level controller

Discussion in 'iOS Programming' started by softwareguy256, Jun 13, 2010.

  1. softwareguy256 macrumors regular

    Joined:
    Jun 5, 2010
    #1
    My application uses a UITabViewController as the root controller with 4 buttons. Part of the app consists of educational content which I am writing in HTML. I would like to maximize screen real-estate by removing the tab-bar.

    So what I would like to do is to use a UINavigationBarController with a UIWebView. I want a back button so the user can go back to exactly where he was before launching this web tool, which will be launched from a help button from a view underneath the tab bar controller.

    I am not sure how to do this.
     
  2. HawaiiMacAddict macrumors 6502a

    Joined:
    Dec 28, 2006
    Location:
    On one of my Macs of course
    #2
    Aloha softwareguy256,

    In my apps, for example NavySpeak, I did exactly what you're looking to do. You don't have to do exactly what I did, but here are the steps I took:

    1. Create a new view controller (UIWebViewController class)
    2. In the call to present the new view controller (in this case called myWebView), used the following code:

    Code:
    [self.navigationController presentModalViewController:myWebView animated:YES];
    In this way, the new view controller covers both the navigation bar and the tabbar controller. You'll have to add a web view, a tabbar, and a tabbar button at the very least. The web view, obviously, holds the web content, but the tabbar and tabbar button are for the done button. You'll also have to add the coding for the done button (to release the modal web view).

    I would suggest that you review the UIWebView documents on the Developer site, then Google web view tutorials to see how the process works.

    My approach uses a modal view controller, which means it covers everything. It you don't want to cover the navigation bar (and not need to have the tabbar with the done button on the bottom), you can also just push the view controller as normal and choose not to display the tabbar (in IB, the view object has a drop-down list for the bottom bar, of which none is the option for no tabbar to be displayed). The code to call up the view controller changes just a little bit, like so:

    Code:
    [self.navigationController pushViewController:myWebView animated:YES];
    The one thing you'll also want to do is to create custom back button text. This is for the back button (automatically create when using a navigation bar) in the left-hand corner of your navigation bar. This is the code I use:

    Code:
    	
    self.title = @"My View";
    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"My View"  style:UIBarButtonItemStyleBordered  target:nil  action:nil];
    self.navigationItem.backBarButtonItem = backButton;
    [backButton release];
    
    In this case, this code is put in the viewDidLoad method of the view controller class that calls up the web view. That way, when your web view is presented, the title of backButton is displayed in the back button on the webview itself. If you need more information, zag me an email at: whjones@crispinworks.com.
     

Share This Page