基于Tabbar的应用程序中的ABPeoplePickerNavigationController

时间:2011-09-29 14:45:22

标签: iphone ipad addressbook

我有如下要求,就像在基于tabbar的应用程序中显示ABPeoplePickerNavigationController一样。我在网上进行了很多研究,发现没有任何有用的答案,只有一个here,如下实现代码将有助于在tabbar中获取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委托。我想覆盖以下委托方法

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

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

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

欢迎任何技巧。我假设我可以继承ABPeoplePickerNavigationController并执行某些操作,但不知道该怎么做。

修改 设置委托后,当我点击“联系人”选项卡时,我遇到了崩溃。

#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

3 个答案:

答案 0 :(得分:3)

在awakeFromNib中创建ABPeoplePickerNavigationController后,需要设置它。添加以下行:

nav.peoplePickerDelegate = self;

这会将您的自定义视图控制器设置为人员选择器的委托。您的控制器需要实现ABPeoplePickerNavigationControllerDelegate协议,您需要实现您在问题中列出的两种方法。

答案 1 :(得分:1)

您是否尝试过设置nav.peoplePickerDelegate = self;

-(void)awakeFromNib
{
    ABPeoplePickerNavigationController *nav = [[ABPeoplePickerNavigationController alloc] init];   
    nav.peoplePickerDelegate = self;
    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];
}

在您的@interface中,您可以表明您是ABPeoplePickerNavigationControllerDelegate的代表:

@interface MyCustomViewController : UIViewController <ABPeoplePickerNavigationControllerDelegate> {

    // ....
}

答案 2 :(得分:1)

最后,我们在应用程序委托中选择了picker控制器,并通过从tabBarController视图控制器数组中获取viewcontroller来设置其委托。