2011-09-29 33 views
4

我有如下要求,如在基于tabbar的应用程序中显示ABPeoplePickerNavigationController。我在网上研究了很多,发现没有有用的答案,但一个here,实现代码如下所示,将有助于在tabbar中获取ABPeoplePickerNavigationController,如图所示。基于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 hereenter image description here

回答

1

最后我们安下心与服用选择器控制器应用程序委托并仅通过从tabBarController视图控制器数组中获取viewcontroller来设置其委托。

3

您需要设置的ABPeoplePickerNavigationController的代表已在awakeFromNib创建后。添加此行:

nav.peoplePickerDelegate = self; 

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

+0

Thax。我实现为nav.peoplePickerDelegate = self;但我碰到像这个问题的应用程序崩溃http://stackoverflow.com/questions/7068848/ios-devproblem-uimorenavigationcontroller-and-abpeoplepickernavigationcontroller –

+0

如果我不设置委托工作正常,但委托方法不会被调用,因为它是没有设置。 –

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> { 

    // .... 
} 
+0

Thax。我实现为nav.peoplePickerDelegate = self;但我碰到像这个问题的应用程序崩溃http://stackoverflow.com/questions/7068848/ios-devproblem-uimorenavigationcontroller-and-abpeoplepickernavigationcontroller –

+0

如果我不设置委托工作正常,但委托方法不会被调用,因为它是没有设置。 –

相关问题