简体   繁体   中英

Universal navigation bar in reusable UIViewController

I have a UIViewController, which is the part of my static library. This UIViewController might be used in different Apps. Some Apps should be able to present this view in navigation style another using present modal.

The question is: what is the elegant way to design this UIViewController concerning the navigation bar? Currently I have the following solution:

- (void)viewDidLoad
{
    [super viewDidLoad];
    if (self.navigationController != nil) {
        self.navigationItem.title = @Test;
        //... set nav bar buttons

    } else {
        UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
        navBar.topItem.title = @Test;
       //... set nav bar buttons and add UINavigationBar to view
    }

}

well the elegant way would be to add your universal UIViewController to the UINavigationController

Its pretty useful that way.

As of iOS 5 Apple added UIViewController containers. This allows you to write classes that behave like UINavigation Controllers.

You use the addChildViewController: method to add another view controller to your hierarchy, you can then draw the views of the View Controllers however you want.

This page of Apple's docs has all the information you need http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/AboutViewControllers/AboutViewControllers.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM