UITabBarController中的ABPeoplePickerNavigationController和UITableViewController

时间:2011-03-07 17:28:41

标签: iphone uitabbarcontroller abpeoplepickerview

请看下面我自己的答案,我在数小时后发现了这个问题。希望我能节省一些时间。

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

我已经搜遍了所有尝试获得解决方案的方法(我是TabBarControllers的新手),并且迄今为止尝试以编程方式进行一点点成功,并且在Interface Builder中完全没有成功,我所看到的只是一个白色的屏幕。

是否有一些图书馆已经做了一些接近这个的东西,我似乎无法找到联系人和收藏夹?

以下是我在两种方法中尝试过的细节,以及它是如何工作的:

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

IB: 我尝试了大量的东西,并且在尝试以模态方式呈现时总是只有白色屏幕。

1 个答案:

答案 0 :(得分:2)

我有两个标签,一个是ABPEoplePickerNavigationController,另一个是昨晚工作的表视图。我希望这可以帮助别人。请注意,您仍然需要将协议添加到选择器的当前视图控制器中,将两个协议添加到tableview中,然后将每个协议的代理函数添加到代码中。如果您不知道要采用哪种协议或编写函数,请查看每个协议的apple dev文档。

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];