在ABPeoplePickerNavigationController中自定义表格单元格 [英] Customizing table cell in ABPeoplePickerNavigationController

查看:150
本文介绍了在ABPeoplePickerNavigationController中自定义表格单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了一些时间在SO上搜索这个答案,但找不到它,所以这里是:

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

我开始使用ABPeoplePickerNavigationController,当用户点击一个人时,他们将被带到ABPersonViewController,在那里他们将能够选择电话号码和电子邮件地址。完成ABPersonViewController后,它们将被带回ABPeoplePickerNavigationController。非常简单的东西。

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.

我想要的是在他们选择电话号码或电子邮件地址后,在他们在ABPeoplePickerNavigationController中选择的表格单元格中添加detailLabel。类似选择的电子邮件和电话号码或选择的电话号码。

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的文档说:


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

提供的委托方法不会处理此问题。有没有办法在没有自我子类化的情况下实现这一目标?并且,如果我必须继承ABPeoplePickerNavigationController的子类,我将覆盖哪个方法来更新detailLabel?

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?

谢谢!

推荐答案

这段代码似乎对我有用,当用户选择一个人并添加一个复选标记时,它会抓取单元格。我猜你也可以在其他方面调整单元格。

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

这篇关于在ABPeoplePickerNavigationController中自定义表格单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆