如何在用户返回视图控制器时取消select一个可用视图单元格
我有一个uitableview单元格突出显示,当用户select,然后推到一个细节视图。 我希望单元格返回到表视图视图控制器时不被注意。
我将如何去完成这个?
我猜[cell.textLabel setHighlighted:NO];
如果我把它放在那里,细胞是不申报的。
谢谢你的帮助
如果您使用UITableViewController
子类,那么只需设置属性
self.clearsSelectionOnViewWillAppear = YES;
其他的viewDidAppear只是调用
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: animated) }
Swift 3.0
override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) if let selectionIndexPath = self.tableView.indexPathForSelectedRow { self.tableView.deselectRow(at: selectionIndexPath, animated: animated) } }
我决定做出这个答案而不是评论。
如果您正在使用故事板 :单击您的UITableViewController – >检查“select:清除外观”框中
尝试
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // Deselect the row which was tapped [tableView deselectRowAtIndexPath:indexPath animated:YES]; }
或者一些不雅的方式=)
NSArray *arrayWithPaths = [tableView indexPathsForVisibleRows]; for (NSIndexPath *path in arrayWithPaths) { [tableview deselectRowAtIndexPath:path animated:NO]; }
迅速3
func clearOnAppearance() { for indexPath in tableView.indexPathsForSelectedRows ?? [] { tableView.deselectRow(at: indexPath, animated: true) } }