views:

385

answers:

2

In my tableview I have number of rows that have disclosure detail button accessory type, and when pressing the row or the accessory, a new view is pushed to a navigation controller. I call the deselectRowAtIndexPath at the end of the didSelectRowAtIndexPath function.

If I press the accessory button, I go to a new view, but it remains highlighted when I come back to this view (pop). The row is deselected as expected but not this. Any thoughts on how to 'unhighlight' it?

cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    ...
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    }
    - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
     [tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionTop];
     [self tableView:tableView didSelectRowAtIndexPath:indexPath];
    }
A: 

Simply remove from your

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath;

method the statement

[tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionTop];

Since your table already allows selection, and you are correctly deselecting it in

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;

you are done, because the row will be highlighted when selected pressing the disclosure button, and deselected when tableView:didSelectRowAtIndexPath: is executed.

unforgiven
That worked to deselect the accessory, but the entire row does not highlight when I press the accessory button. Is there any way to achieve this?
Rob
You are right, the row is not highlighted. However, the Apple HIG does not mandate highlighting the entire row when tapping the disclosure button. All of my applications work as described, including those available on the AppStore.
unforgiven
Fair enough, thanks for the help.
Rob
A: 

For those who are still bothered by this and want a solution that appears to work right now, try this:

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {

[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:NO];
[tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];

}

You must reload the data FIRST and THEN select the row so that the highlight appears beneath your action sheet options.

TheNeverStill