0

请参阅下面的我自己的答案,我在几个小时后想通了。希望我能节省一些时间。

我目前在我的 UI 上有一个按钮,它将模态显示一个 ABPeoplePickerNavigationController,它工作得很好。我想扩展它以实现收藏夹和最近更新,这样当用户点击按钮时,我会呈现一个 UITabBarController,其中一个选项卡上有 ABPeoplePickerNavigationController,然后是另外两个带有收藏夹和最近更新的选项卡(我猜这将是 UITableViewControllers . 我基本上希望标签栏控制器的行为类似于内置电话应用程序的模式版本,用于联系人、收藏夹和最近的标签(但不仅仅是电话号码)。

我已经到处搜索,试图找到一个关于如何做到这一点的解决方案(我是 TabBarControllers 的新手),到目前为止,我一直试图以编程方式完成它并取得了一点成功,而在 Interface Builder 中却完全没有成功,所有我曾经看到的是一个白色的屏幕呈现。

是否有一些图书馆已经做了一些我似乎无法找到联系人和收藏夹的事情?

以下是我在这两种方法中尝试过的内容及其工作原理的细分:

以编程方式:我基本上创建了 ABPeoplePickerNavigationController,就像我打算单独以模态方式呈现它一样,而是使用 setViewControllers 方法将它添加到 UITabBarController 实例。当我展示这个时,选项卡上显示“组”,我无法弄清楚如何将图标更改为联系人的系统图标,或者更改按下选项卡栏按钮的行为以不退出组(当您按下标签栏按钮时,内置电话应用程序不会备份到该级别)。就像我上面提到的,我基本上希望它的行为类似于用于联系人、收藏夹和最近的内置电话应用程序。

IB:我尝试了很多东西,但在尝试以模态方式呈现时总是只得到一个白屏。

4

1 回答 1

2

我有两个选项卡,一个带有 ABPEoplePickerNavigationController,另一个带有昨晚工作的表格视图。我希望这可以帮助别人。请注意,您仍然必须将协议添加到当前视图控制器的选取器和两个用于 tableview 的协议,然后将每个的委托函数添加到您的代码中。如果您不知道要采用哪些协议或编写功能,请查看每个的 Apple 开发文档。

ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
UITabBarItem *peoplePickerTabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemContacts tag:0];
picker.tabBarItem = peoplePickerTabBarItem;
UITableViewController *tvc = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
tvc.tableView.delegate = self;
tvc.tableView.dataSource = self;
UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:tvc];
UIBarButtonItem *uibbiCancel = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStylePlain target:self action:@selector(cancelTable)];
tvc.navigationItem.rightBarButtonItem = uibbiCancel;
tvc.title = @"Recents";
UITabBarItem *nvcTabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemRecents tag:2];
nvc.tabBarItem = nvcTabBarItem;
tbc = [[UITabBarController alloc] init];
NSArray *sections = [[NSArray alloc] initWithObjects:picker, nvc, nil];
[tbc setViewControllers:sections];
[self presentModalViewController:tbc animated:YES];
[nvcTabBarItem release];
[uibbiCancel release];
[tvc release];
[peoplePickerTabBarItem release];
[picker release];
[nvc release];
[sections release];
[tbc release];
于 2011-03-08T16:29:07.890 回答