【发布时间】:2010-05-16 18:00:07
【问题描述】:
我想像使用“ABPeoplePickerNavigationController”一样启动一个模态视图控制器,而无需创建包含视图控制器的导航控制器。
执行类似操作会产生一个空白屏幕,导航栏没有标题,并且即使我在调用“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
Apple 的“视图控制器编程指南”中建议的创建模态视图的另一种方法 iPhone 操作系统:
// 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 相同的方式启动?
【问题讨论】:
标签: iphone