我花了一些时间在 SO 上搜索这个答案,但找不到,所以这里是:
我从一个 ABPeoplePickerNavigationController 开始,当用户点击一个人时,他们将被带到一个 ABPersonViewController,在那里他们可以选择电话号码和电子邮件地址。在他们完成 ABPersonViewController 之后,他们将被带回 ABPeoplePickerNavigationController。非常简单的东西。
我想要的是在他们选择电话号码或电子邮件地址后,将 detailLabel 添加到他们在 ABPeoplePickerNavigationController 中选择的表格单元格中。类似于“选择的电子邮件和电话号码”或“选择的电话号码”。
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/