2011-03-07 85 views
0

請參閱下面的我自己的答案,我在數小時後計算出來。希望我能省些時間。UITabBarController中的ABPeoplePickerNavigationController和UITableViewController

我目前在我的用戶界面上有一個按鈕,它會以模態方式呈現ABPeoplePickerNavigationController,它工作得很好。我想擴展這個來實現收藏夾和最近,這樣當用戶點擊按鈕時,我會呈現一個UITabBarController,它在一個選項卡上有ABPeoplePickerNavigationController,然後是兩個其他選項卡,包括收藏夾和最近點(我猜測它將是UITableViewControllers 。我基本上希望標籤欄控制器的行爲像內置的手機應用程序的聯繫人,收藏夾和最近標籤的模態版本(但不只是電話號碼)

我已經遍尋全部試圖獲得解決方案如何做到這一點(我是TabBarControllers的新手),並且迄今爲止試圖通過一些成功的方式以編程的方式完成它,而在界面生成器中絕對沒有成功,我所見過的只是一個白色屏幕。

Is there一些圖書館已經做了一些我似乎無法找到的聯繫方式和收藏夾?

下面是我在這兩種方法已經試過擊穿,以及它是如何工作:

編程: 我基本上創造的ABPeoplePickerNavigationController像我正想模態單獨存在的,而是將其添加到UITabBarController實例使用setViewControllers方法。當我這樣做時,選項卡上會顯示「Groups」,我不知道如何將圖標更改爲聯繫人的系統圖標,或更改按下選項卡欄按鈕的行爲以便不退出到組中(當您按下標籤欄按鈕時,內置的手機應用程序不會備份到該級別)。就像我上面提到的,我基本上希望它的行爲類似於內置的手機應用程序的聯繫人,收藏夾和最近。

IB: 我嘗試了大量的東西,並試圖以模態方式呈現時總是隻能看到白色屏幕。

回答

2

我得到了兩個選項卡,一個使用ABPEoplePickerNavigationController,另一個使用昨晚的表格視圖。我希望這可以幫助別人。請注意,您仍然必須將協議添加到picker的當前視圖控制器,將兩個協議添加到tableview,然後將每個代理函數添加到您的代碼中。如果您不知道要採用哪種協議或要編寫哪些協議,請查看每個Apple Devs文檔。

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]; 
相關問題