deselectRowAtIndexPath on an ABPeoplePickerNavigat

2019-04-09 02:12发布

I'm showing an ABPeoplePickerNavigationController as a tab in my app. The user clicks a name, then email address, then I do something with the email address.

Afterwards, I'd like for the person and property that they selected to fade out (not be highlighted).

In a normal table, I'd call deselectRowAtIndexPath. But with the ABPeoplePickerNavCont I don't seem to have access to it's table, nor do I know what indexPath is selected, nor is there an api for deselecting the row.

On most apps, ABPeoplePickerNavCont is used modally so it doesn't matter that the row is still highlighted 'cause the whole thing gets dismissed. But in my app it does not get dismissed (just like the contacts tab in the Phone app).

Any ideas?

3条回答
Explosion°爆炸
2楼-- · 2019-04-09 02:51

This is what I'm doing... and it seems to work perfectly. I'm also adding a checkmark accessory when you select/deselect an item. Let me know what you think. Thanks :)

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

    cell.accessoryType = cell.accessoryType == UITableViewCellAccessoryNone ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;

    [cell setSelected:NO animated:YES];
}
查看更多
贪生不怕死
3楼-- · 2019-04-09 03:02

Modifying robby valles' answer, this is how I deselect the tableview of ABPeoplePickerNavigationController:

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

    cell.accessoryType = cell.accessoryType == UITableViewCellAccessoryNone ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;

    [tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:YES];
}

Hope this helps.

查看更多
ら.Afraid
4楼-- · 2019-04-09 03:13

dismiss the peoplepicker without an animation, then present it again without animation. It looks good.

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person{

    [self dismissModalViewControllerAnimated:NO];

    [self presentModalViewController:peoplePicker animated:NO];
        return NO;
 }
查看更多
登录 后发表回答