How to perform a cell deselection when a user returns to a table view?

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-06 05:37:09

问题


I am using a UITableView to display a list of cells, when the user selects a cell then a new view appears by using the following code:

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
     [self.navigationController pushViewController: detailsViewController animated: TRUE];
}

By using the code above, the view is displayed correctly, but when I return back to the root table view, then the cell is still selected. I noticed, in many sdk examples, that the cell is deselected (with a nice animation) when the root view is poped pack, but I could not find the code that implemented this feature in any of the examples. I know that I can use:

[tableView deselectRowAtIndexPath:indexPath animated: YES];

to implement this, but I am very curious on how these examples do it without using any code.

Any ideas?


回答1:


UITableViewController automatically handles this for you when you call super in viewDidAppear: etc. So the easiest way to achieve this is to subclass UITableViewController. If you can't (e.g. because the table is just a part of a more complex view), then you'll have to do it yourself in the viewDidAppear: method. (You should also flash the scrollers, too).



来源:https://stackoverflow.com/questions/777321/how-to-perform-a-cell-deselection-when-a-user-returns-to-a-table-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!