在 ABPeoplePickerNavigationController 中自定义表格单元格

发布于 10-21 20:22 字数 870 浏览 5 评论 0原文

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

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

我想要的是在他们选择电话号码或电子邮件地址后,将详细标签添加到他们在 ABPeoplePickerNavigationController 中选择的表格单元格中。例如“选择的电子邮件和电话号码”或“选择的电话号码”。

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?

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

面犯桃花2024-10-28 20:22:27

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

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

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;
}
鸠魁2024-10-28 20:22:27

我知道如何做到这一点,我认为这会对您有所帮助,但从未像这样实施过。
首先,您必须使用自定义表格。对于该表,您可以提供地址簿中的所有联系人姓名。您可以使用 http:// /developer.apple.com/library/mac/#documentation/userexperience/Reference/AddressBook/Classes/ABAddressBook_Class/Reference/Reference.html

只要浏览一下就可以理解。

你必须使用这些方法。
1) - (NSArray *)人
您会将所有人员记录放入返回的数组中。每条记录都有唯一的 id ,您必须检索它

ABRecord rec = [returnedArray objectAtIndex:0];

NSString *pid = rec.uniqueId

-(NSString *) uniqueId (这是 ABRecord 属性方法)

一旦获得它,您就可以通过使用该 recordid/unique id 从数组中退出您想要的内容。

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 .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文