iphone - 基于 Tabbar 的应用程序中的 ABPeoplePickerNavigationController

标签 iphone ipad addressbook

我有如下要求,例如在基于选项卡栏的应用程序中显示 ABPeoplePickerNavigationController。我在网上进行了很多研究,除了一个here之外没有找到任何有用的答案。 ,实现如下代码将有助于在选项卡栏中获取ABPeoplePickerNavigationController,如图所示。

第一个屏幕截图是我运行应用程序时的直接结果,第二个屏幕截图是我再次单击“联系人”选项卡时的结果(很奇怪,但确实如此)。

-(void)awakeFromNib
{
    ABPeoplePickerNavigationController *nav = [[ABPeoplePickerNavigationController alloc] init];   
    NSMutableArray *newControllers = [NSMutableArray arrayWithArray: [self.tabBarController viewControllers]];
    int index = [newControllers indexOfObject: self];  
    [newControllers replaceObjectAtIndex: index withObject: nav];
    [self.tabBarController setViewControllers: newControllers animated: NO];
    [nav release];
}

现在我的问题是我能够浏览联系人,但无法设置 ABPeoplePickerNavigationController 委托(delegate)。我想重写以下委托(delegate)方法

-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier
{
}

-(BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person 
{
}

我无法设置,因为我不知道在哪里设置委托(delegate)。请帮助我,因为我的项目已截止,所有其他功能均已完成。

欢迎任何技巧。我假设我可以继承 ABPeoplePickerNavigationController 并做一些事情,但不知道该怎么做。

编辑 设置委托(delegate)后,当我单击“联系人”选项卡时,我遇到以下崩溃。

#0  0x00f85057 in ___forwarding___
#1  0x00f84f22 in __forwarding_prep_0___
#2  0x00d4b678 in -[ABMembersViewController membersController:shouldAllowSelectingPerson:]
#3  0x00d1df85 in -[ABMembersController abDataSource:shouldAllowSelectingPerson:]
#4  0x00d9abb9 in -[ABMembersDataSource tableView:cellForRowAtIndexPath:]
#5  0x003357fa in -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:]
#6  0x0032b77f in -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:]
#7  0x00340450 in -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:]
#8  0x00338538 in -[UITableView layoutSubviews]
#9  0x01dc8451 in -[CALayer layoutSublayers]
#10 0x01dc817c in CALayerLayoutIfNeeded
#11 0x01dc137c in CA::Context::commit_transaction
#12 0x01dc10d0 in CA::Transaction::commit
#13 0x01df17d5 in CA::Transaction::observer_callback
#14 0x00ff4fbb in __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__
#15 0x00f8a0e7 in __CFRunLoopDoObservers
#16 0x00f52bd7 in __CFRunLoopRun
#17 0x00f52240 in CFRunLoopRunSpecific
#18 0x00f52161 in CFRunLoopRunInMode
#19 0x018b5268 in GSEventRunModal
#20 0x018b532d in GSEventRun
#21 0x002d042e in UIApplicationMain
#22 0x00002240 in main at main.m:13

enter image description here enter image description here

最佳答案

在 awakeFromNib 中创建 ABPeoplePickerNavigationController 后,您需要设置它的委托(delegate)。添加这一行:

nav.peoplePickerDelegate = self;

这会将您的自定义 View Controller 设置为人员选择器的委托(delegate)。您的 Controller 需要实现 ABPeoplePickerNavigationControllerDelegate 协议(protocol),并且您需要实现问题中列出的两种方法。

关于iphone - 基于 Tabbar 的应用程序中的 ABPeoplePickerNavigationController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7599090/

相关文章:

iphone - 读取数组

iphone - 通过非 AppStore 销售 iOS 应用程序

ios - 不同 subview 之间的 iPad 导航

iphone - iOS 5 JSON 分级别解析

ios - 一个 View Controller 中的两个 TableView

ios - 定位 MKMapView 以一次显示多个注释

iphone - iOS:在运行时以编程方式添加自定义字体

iOS - 内存泄漏地址簿

iphone - 地址簿:尝试添加 'Home' 和 'Work' 地址,但只显示 1 个

java - 比较人名以检测相同性的算法