Running modal UINavigationController

I would like to run the modal view controller in the same way as with "ABPeoplePickerNavigationController", and it does not need to create a navigation controller containing a view controller.

Doing something like this gives a blank screen without a title for the navigation bar, and there is no associated nib file loaded for presentation, although I call initWithNibName when init is called.

My controller looks like this:

@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 

Another way to create a modal view, as suggested in the Apple View View 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 perfectly (as long as I change MyViewController to inherit with UIViewController instead of UINavigationController). What else should I do with MyViewController to run in the same way as ABPeoplePickerNavigationController?

+6
iphone
source share
1 answer

I would like to start the modal view controller in the same way as with the "ABPeoplePickerNavigationController", and without creating a navigation controller containing the view controller.

But this is exactly what ABPeoplePickerNavigationController does. This is not magic, it is a UINavigationController that installs the UIViewController internally (a UITableView that is populated with the contacts in your address book) and sets the UIViewController as the root view.

You really can create your own similar subclass of UINavigationcontroller. However, inside this initializer, you will need to create a view controller for loading as its root view, as ABPeoplePickerNavigationController does.

Then you can do what you are trying to do so:

 [self presentModalViewController:myCutsomNavigationController animated:YES]; 

In the code you sent:

 @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 

I suspect you have problems with the NIB. there is no "rootViewController" connector for connection. That is why you have a blank screen.

The initializer you should use internally is the following:

 self = [super initWithRootViewController:myCustomRootViewController]; 
+4
source share

All Articles