Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using UINavigationBar without UINavigationController

I want a UINavigationBar at the top of my UIWebView but I want to control by hand the title, the back button, what the back button does - etc. In other words I never want to push or pop views. I just want to change the UINavigationBar contents as the user clicks around the web view.

Where I'm up to is I added the UINavigationBar to my superView and made it 44 pixels tall. How do I set the title since I have no navigationItem? How would I set a fake back button up?

I would appreciate any pointers. I realise this is quite weird what I'm doing.

Thanks :)

like image 677
Mike S Avatar asked Feb 08 '12 06:02

Mike S


Video Answer


1 Answers

The answer, if anyone's interested, is in the class reference of UINavigationBar.

When you use a navigation bar as a standalone object, you are responsible for providing its contents. Unlike other types of views, you do not add subviews to a navigation bar directly. Instead, you use a navigation item (an instance of the UINavigationItem class) to specify what buttons or custom views you want displayed. A navigation item has properties for specifying views on the left, right, and center of the navigation bar and for specifying a custom prompt string.

In short, use a UINavigationItem and apply it by "pushNavigationItem" on the UINavigationBar.

I created a subclass of UINavigationBar called StaticNavigationBar which I can then load with any state by putting the appropriate UINavigationItem's on it. Thanks for all your answers people.

like image 168
Mike S Avatar answered Sep 27 '22 21:09

Mike S