当用户选择uitableview单元格,然后将其推送到详细视图时,该单元格将突出显示。我希望单元格在返回到表视图视图控制器时不突出显示。
我该如何去实现这个目标呢?
我猜是viewWillAppear中的[cell.textLabel setHighlighted:NO];
,但是如果我把它放在那里,它就是未声明的。
谢谢你的帮助
发布于 2013-02-19 19:56:54
如果使用UITableViewController
子类,则只需设置属性
self.clearsSelectionOnViewWillAppear = YES;
否则在viewWillAppear
中只需调用
NSIndexPath *indexPath = self.tableView.indexPathForSelectedRow;
if (indexPath) {
[self.tableView deselectRowAtIndexPath:indexPath animated:animated];
}
// MARK: - Swift 3
if let indexPath = tableView.indexPathForSelectedRow {
tableView.deselectRow(at: indexPath, animated: true)
}
发布于 2013-02-19 19:56:13
试一试
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Deselect the row which was tapped
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
发布于 2017-06-20 22:18:10
swift 3
func clearOnAppearance() {
for indexPath in tableView.indexPathsForSelectedRows ?? [] {
tableView.deselectRow(at: indexPath, animated: true)
}
}
https://stackoverflow.com/questions/14956823
复制相似问题