当返回到 -viewWillAppear:animated
中的 TableView 时,我使用以下代码取消选择选定的 TableView 单元格。
[self.tableView deselectRowAtIndexPath:self.tableView.indexPathForSelectedRow animated:YES];
在这种情况下,我还需要重新加载表格 View 的数据,但是当您这样做时,它会清除所选单元格的选定状态,因此您看不到任何淡入淡出动画。
有没有办法重新加载表格数据并保留选定状态以创建取消选择动画?
最佳答案
经过多次尝试,我发现了一些可行的方法。您需要将取消选择设置为在“延迟”(0 秒)后发生,以确保它发生在下一个绘制周期并正确设置动画。
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSIndexPath *indexPath = self.tableView.indexPathForSelectedRow;
[self.tableView reloadData];
[self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
[self performSelector:@selector(deselectRow) withObject:nil afterDelay:0];
}
- (void)deselectRow
{
[self.tableView deselectRowAtIndexPath:self.tableView.indexPathForSelectedRow animated:YES];
}
关于ios - tableView reloadData 和 deselectRowAtIndexPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27711850/