Customizing table cell in ABPeoplePickerNavigationController
Asked Answered
D

2

12

I've spent some time searching for this answer on SO, but couldn't find it, so here goes:

I'm starting with an ABPeoplePickerNavigationController, and when a user taps a person, they'll be taken to an ABPersonViewController where they'll be able to select phone numbers and email addresses. After they're finished with the ABPersonViewController, they'll be taken back to the ABPeoplePickerNavigationController. Pretty simple stuff.

What I want is to add a detailLabel to the table cell they selected in ABPeoplePickerNavigationController after they chose a phone number or an email address. Something like "Email and phone number chosen" or "Phone number chosen".

Apple's documentation says:

 You should not need to subclass these controllers; the expected way to modify their behavior is by your implementation of their delegate.

The delegate methods provided won't handle this. Is there any way to accomplish this without subclassing myself? And, if I do have to subclass ABPeoplePickerNavigationController, which method would I override to update the detailLabel?

Thanks!

Diaconate answered 11/3, 2011 at 8:14 Comment(1)
I want to do this kind of thing also but it looks like it's not possible. I'm going to have to re-create a people picker look-alike pageBlanketing
T
12

This bit of code seems to work for me, it grabs the cell when the user selects a person and adds a check mark. I'm guessing you can tweak the cell in other ways at this point as well.

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person{
UIView *view = peoplePicker.topViewController.view;
UITableView *tableView = nil;
for(UIView *uv in view.subviews)
{
    if([uv isKindOfClass:[UITableView class]])
    {
        tableView = (UITableView*)uv;
        break;
    }
}
if(tableView != nil)
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:[tableView indexPathForSelectedRow]];
    if(cell.accessoryType == UITableViewCellAccessoryNone){
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
    else{
        cell.accessoryType = UITableViewCellAccessoryNone;
    }        
    [cell setSelected:NO animated:YES];
}
return NO;
}
Tusche answered 2/5, 2012 at 17:16 Comment(2)
I ended up rolling my own, but this solution looks great. Thanks for adding this!Diaconate
Doesn't work out so well for the cells that are displayed during a search.Midmost
V
0

I have idea of how to do it, i think it will be helpful to you , but never implemented like this. First you have to go with custom table . For that table you can give all the contact names from your addressbook. you can use http://developer.apple.com/library/mac/#documentation/userexperience/Reference/AddressBook/Classes/ABAddressBook_Class/Reference/Reference.html

just go through it you can understand .

you have to use these methods. 1) - (NSArray *)people you will get all people records into returned array. each record will have unique id , you have to retrieve it

ABRecord rec = [returnedArray objectAtIndex:0];

NSString *pid = rec.uniqueId

-(NSString *) uniqueId ( this is ABRecord property method )

once you got it you can retireve from your array what you want by using that recordid/ unique id .

Viceregal answered 11/3, 2011 at 10:19 Comment(1)
Thanks Ramesh. I was trying to avoid rebuilding the table view using records from the Address Book, mostly because the ABPersonPickerNavigationController automatically places the last name or the first name in bold depending on the users sort preferences. I'm not too familiar with the NSAttributedString class, but perhaps I should brush up and just rebuild the table myself.Diaconate

© 2022 - 2024 — McMap. All rights reserved.