iphone - 在 ABPeoplePickerNavigationController 中自定义表格单元格

标签 iphone objective-c ios uitableview abaddressbook

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

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

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

Apple's documentation说:

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

提供的委托(delegate)方法不会处理这个。有没有办法在不对自己进行子类化的情况下实现这一目标?而且,如果我确实必须继承 ABPeoplePickerNavigationController,我应该重写哪个方法来更新 detailLabel?

谢谢!

最佳答案

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

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

关于iphone - 在 ABPeoplePickerNavigationController 中自定义表格单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5270482/

相关文章:

objective-c - 水平 ScrollView IOS 的建议

ios - 折线不会出现在 MapKit 中

ios - 在 react-native 中如何检测右半边屏幕是否被点击?

iphone - 在 Snow Leopard 上针对 2.2.1 SDK 进行开发

iphone - 从窗口中移除时 UIScrollview contentOffset 发生变化

ios - 制作一个内部有3个屏幕的屏幕并使用分段控件

iphone - 理解 Objective-C 中的@Protocols

ios - Facebook SDK 错误 : FBSDKVersion-generated. 未找到 h 文件

iphone - AudioQueuePrime 失败并显示 -66674

iphone - NSDictionary 上的快速枚举失败,错误代码为 "[Waypoint countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance ..."