开发者

AccessoryDetailDisclosureButton not deselecting after I call deselectRowAtIndexPath

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


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:UITableViewRowAnimationNone];
[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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜