我想用'ABPeoplePickerNavigationController'来启动一个模态视图控制器,而不需要创建一个包含视图控制器的导航控制器。启动一个模态UINavigationController
做类似的事情会产生一个空白的屏幕,导航栏没有标题,即使我在调用'init'时调用initWithNibName,也没有为视图加载关联的nib文件。
我的控制器看起来像:
@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
当使用AB控制器,你要做的就是:
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
[self presentModalViewController:picker animated:YES];
[picker release];
的ABPeoplePickerNavigationController声明为:
@interface ABPeoplePickerNavigationController : UINavigationController
的另一种方式创建一个模式视图,如苹果的'视图控制器编程指南“中所建议的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];
我可以创造这种方式细(只要我改变MyViewController为继承的UIViewController而不是UINavigationController的)。我还应该如何对MyViewController启动与ABPeoplePickerNavigationController相同的方式?