deselectRowAtIndexPath on an ABPeoplePickerNavigat

2019-04-09 03:00发布

问题:

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?

回答1:

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


回答2:

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.



回答3:

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