Question

My navigationController pushes another view controller which is a UIWebView. I need to a back button and a forward button to control the UIWebView.

I have three questions here:

  1. I found navigationController has a toolbar and I can just set the toolbar to be visible and add buttons to it, but I don't know I should add buttons to the toolbar or just to the navigation bar (what do pros do)?

  2. Does UIWebView have its own toolbar that can be inside the webView? I did some research and found an answer which made me even more confused and led to the third question.

  3. After I init a toolbar, a webView and add them to another view as subviews, do I need to manually release their ownership? (I found the code below in a question answered in 2010)

Thanks!

    UIWebView *webView = [[UIWebView alloc] initWithFrame:.....];
    [yourView addSubview:webView];
    UIToolBar *toolbar = [[UIToolbar alloc] initWithFrame:.....];
    [yourView addSubview:toolbar];
    [webView release];
    [toolbar release];
Was it helpful?

Solution

Any view controller that is pushed onto a navigation controller gets a free navbar and a free toolbar from the navigation controller. So there is no need to create another toolbar. Simply add code in the view controller to show the toolbar. Something like:

self.navigationController.toolbarHidden = NO;

Personally I would add the next/prev buttons for your web view on the toolbar. This leaves the navbar for dismissing the view controller (via the back button).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top