在ABUnknownPersonViewController中添加导航栏

时间:2011-05-20 13:26:58

标签: iphone objective-c ios

ABUnknownPersonViewController *unknownPersonViewController = [[ABUnknownPersonViewController alloc] init];

unknownPersonViewController.view.frame = CGRectMake(0, 20, 320, 400);

//unknownPersonViewController.displayedPerson = (ABRecordRef)[self buildContactDetails];
unknownPersonViewController.allowsAddingToAddressBook = YES;

UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
cancelBtn.frame = CGRectMake(262, 6, 54,30);
[unknownPersonViewController.view addSubview:cancelBtn];

[self presentModalViewController:unknownPersonViewController animated:YES];

[unknownPersonViewController release]; 

我正在使用UIViewcontroller,在这段代码中,我希望像导航栏这样的栏会显示在上面 这个控制器的一面所以我想在那个栏上放上取消按钮。有什么帮助吗?

2 个答案:

答案 0 :(得分:2)

您应该做的是将您的ABUnknownPersonViewController嵌入到UINavigationController

UINavigationController *newNavigationController = [[UINavigationController alloc] initWithRootViewController:unknownPersonViewController];

[self presentModalViewController:newNavigationController animated:YES];   
[view release];

[newNavigationController release];

这样你甚至不必自己添加按钮,ABUnknownPersonViewController会照顾你。

有关详情,请查看Address Book Programming

答案 1 :(得分:0)

嗯,在线文档说“重要的未知人员视图控制器必须与导航控制器一起使用才能正常运行。”因此,与许多实用程序视图控制器不同,我认为您不应该调用

[self presentModalViewController:unknownPersonViewController animated:YES];

而是

[self.navigationController pushViewController:view animated:YES];

我想如果你看看他们的样品,你会看到他们推动使用导航控制器。