我想用'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相同的方式?