Search code examples
iphoneiosuinavigationcontrolleruinavigationbaruinavigationitem

Write OWN UINavigationController? Similar functionality, not subclassing


I need to have a custom view controller with the same functionality as the UINavigationController. Why I don't use the standard one is because I really need a custom NavigationBar (more than 2 buttons, title and subtitle, different height, etc etc...)

I am trying to implement a custom ViewController with a view acting a s a header, but I can't really get same functionality as the original UINavigationViewController...

How will you implement this?I have spent 2 days playing around (first modifying the appearance of the navigation bar, then creating a custom navigation bar and today creating a custom ViewController)


Solution

  • also take look on View Controller Containment in iOS 5 (you can add child view controllers in iOS 5 and handle the presentation yourself).

    you can use a transparent navigation bar above any other view (flexible size ^^) and use core animation for the transition animation (there are more animation options than in UIKit for the push-pop-animation).

    Be sure to subclass UIViewController and add a special "custonNavigationController" property (weak) to it which you can set from your custom navigationcontroller; use this class as your base view controller class (or, create a protocol which you implement in subclasses of UIViewController, UITableViewController, ... as base classes for these kinds). you "could" overwrite the getter methods for the "old" navigationController property so you can use other (Apple, 3rd party frameworks) view controllers.

    If you want to time your animations perfectly (and not hardcode values - which should be enough), you can also implement the delegate methods for UINavigationBar :)

    So far, this has worked out pretty well in our projects.