[英]select and unselect tableview cell
我要從tableViewControllerOne到tableViewControllerTwo。 發生這種情況時,tableViewControllerTwo滾動到某個單元格。 這很好用,但是, 我希望在滾動后選中或“突出顯示”單元格,然后使其變為未選中/未突出顯示的狀態,因此看起來像其余單元格一樣 。
在我的tableView.scrollToRow(at: indexPath, at: .top, animated: true)
之后,我有tableView.scrollToRow(at: indexPath, at: .top, animated: true)
語句叫做tableView.scrollToRow(at: indexPath, at: .top, animated: true)
我嘗試這樣做而不是tableView.selectRow(at: indexPath, animated: true, scrollPosition: .top)
但是該單元格將保持選中狀態。 我還嘗試了這個tableView.selectRow(at: indexPath, animated: true, scrollPosition: .top) tableView.deselectRow(at: indexPath, animated: true)
但是它們都必須發生得如此之快,以至於我永遠都看不到選中該單元格。
您可以嘗試以我在這里發現的方式延遲deselectRow
函數:
let when = DispatchTime.now() + 2 // change 2 to desired number of seconds
DispatchQueue.main.asyncAfter(deadline: when) {
tableView.deselectRow(at: indexPath, animated: true)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.