开发者

ABPeoplePickerNavigationController in Tabbar based application

开发者 https://www.devze.com 2023-04-10 00:48 出处:网络
I have requirement as following like showing ABPeoplePickerNavigationController in tabbar based application. I researched a lot on net and found no helpful answer but one here, to implement code as fo

I have requirement as following like showing ABPeoplePickerNavigationController in tabbar based application. I researched a lot on net and found no helpful answer but one here, to implement code as follows will help to get ABPeoplePickerNavigationController in tabbar as shown in image.

First screenshot is direct result when I run the application and second screenshot is when I again click on the Contacts tab (Weird but thats true).

-(void)awakeFromNib
{
    ABPeoplePickerNavigationController *nav = [[AB开发者_StackOverflow社区PeoplePickerNavigationController 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];
}

Now my problem is I am able to navigate through contacts but not able to set ABPeoplePickerNavigationController delegate. I want to override following delegate methods

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

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

Which I am not able to set, as I have no idea where to set delegate. Please help me for the same as my project is on Deadline and all other features are completed.

Any tricks are welcomed. I assume that I can subclass ABPeoplePickerNavigationController and do something but don't know how to do that.

Edit After setting delegate I am getting following crash when I click on Contacts tab.

#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

ABPeoplePickerNavigationController in Tabbar based application

ABPeoplePickerNavigationController in Tabbar based application


You need to set the ABPeoplePickerNavigationController's delegate after you have created it in awakeFromNib. Add this line:

nav.peoplePickerDelegate = self;

This sets your custom view controller as the people picker's delegate. Your controller will need to implement the ABPeoplePickerNavigationControllerDelegate protocol and you will need to implement the two methods you have listed in your question.


Have you tried setting nav.peoplePickerDelegate = self; like so:

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

And in your @interface you can indicate that you are the delegate with ABPeoplePickerNavigationControllerDelegate:

@interface MyCustomViewController : UIViewController <ABPeoplePickerNavigationControllerDelegate> {

    // ....
}


Finally We settled down with taking picker controller in application delegate and setting its delegate there only by getting viewcontroller from tabBarController array of view controllers.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号