简体   繁体   English

在ABPeoplePickerNavigationController中自定义表格单元格

[英]Customizing table cell in ABPeoplePickerNavigationController

I've spent some time searching for this answer on SO, but couldn't find it, so here goes: 我花了一些时间在SO上搜索这个答案,但找不到它,所以这里有:

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. 我开始使用ABPeoplePickerNavigationController,当用户点击一个人时,他们将被带到ABPersonViewController,在那里他们将能够选择电话号码和电子邮件地址。 After they're finished with the ABPersonViewController, they'll be taken back to the ABPeoplePickerNavigationController. 完成ABPersonViewController后,它们将被带回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. 我想要的是在他们选择电话号码或电子邮件地址后,在他们在ABPeoplePickerNavigationController中选择的表格单元格中添加detailLabel。 Something like "Email and phone number chosen" or "Phone number chosen". 类似“选择的电子邮件和电话号码”或“选择的电话号码”。

Apple's documentation says: Apple的文档说:

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? 并且,如果我必须继承ABPeoplePickerNavigationController的子类,我将覆盖哪个方法来更新detailLabel?

Thanks! 谢谢!

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

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 你可以使用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. 1) - (NSArray *)人们你会把所有人的记录都归入到返回的数组中。 each record will have unique id , you have to retrieve it 每条记录都有唯一的ID,你必须检索它

ABRecord rec = [returnedArray objectAtIndex:0]; ABRecord rec = [returnedArray objectAtIndex:0];

NSString *pid = rec.uniqueId NSString * pid = rec.uniqueId

-(NSString *) uniqueId ( this is ABRecord property method ) - (NSString *)uniqueId(这是ABRecord属性方法)

once you got it you can retireve from your array what you want by using that recordid/ unique id . 一旦你得到它,你可以使用该recordid /唯一ID从你的阵列中退出你想要的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM