Launching a modal UINavigationController

Posted by Alexi Groove on Stack Overflow See other posts from Stack Overflow or by Alexi Groove
Published on 2009-06-22T22:47:07Z Indexed on 2010/05/16 10:10 UTC
Read the original article Hit count: 463

Filed under:

I'd like to launch a modal view controller the way one does with 'ABPeoplePickerNavigationController' and that is without having to creating a navigation controller containing the view controller.

Doing something similar yields a blank screen with no title for the navigation bar and there's no associated nib file loaded for the view even though I am invoking the initWithNibName when the 'init' is called.

My controller looks like:

@interface MyViewController : UINavigationController

@implementation MyViewController
- (id)init {
    NSLog(@"MyViewController init invoked");
    if (self = [super initWithNibName:@"DetailView" bundle:nil]) {
    	self.title = @"All Things";
    }
    return self;
}
- (void)viewDidLoad {   
    [super viewDidLoad];

    self.title = @"All Things - 2";
}

@end

When using the AB controller, all you do is:

ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;

[self presentModalViewController:picker animated:YES];
[picker release];

ABPeoplePickerNavigationController is declared as:

@interface ABPeoplePickerNavigationController : UINavigationController

The other way to create a modal view as suggested in Apple's 'View Controller Programming Guide for iPhone OS':

// Create a regular view controller.
MyViewController *modalViewController = [[[MyViewController alloc] initWithNibName:nil bundle:nil] autorelease];

// Create a navigation controller containing the view controller.
UINavigationController *secondNavigationController = [[UINavigationController alloc] initWithRootViewController:modalViewController];

// Present the navigation controller as a modal view controller on top of an existing navigation controller
[self presentModalViewController:secondNavigationController animated:YES];

I can create it this way fine (as long as I change the MyViewController to inherit from UIViewController instead of UINavigationController). What else should I be doing to MyViewController to launch the same way as ABPeoplePickerNavigationController?

© Stack Overflow or respective owner

Related posts about iphone