[英]Swift tableView cell subviews flicker (disappear and then reappear) when cell is selected
我有一个带有几个不同子视图的viewCell。 其中之一是带有橙色背景的标签。 现在,当我在表格视图中选择单元格时,标签背景闪烁(消失,然后重新出现)到其原始位置,我看不到是什么导致了此问题。
//my did select func
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// let selectedCell:UITableViewCell = tableView.cellForRow(at: indexPath)!
tableView.deselectRow(at: indexPath, animated: true)
let post = RquestInfoArray[indexPath.row]
if post["status"] as! String == "pending" {
let ac = UIAlertController(title: "My Rquest", message: "Options", preferredStyle: .actionSheet)
let detailAction = UIAlertAction(title: "View Detail", style: .default, handler: { (action) in
tableView.deselectRow(at: indexPath, animated: false)
print("view detail pressed")
})
let deleteAction = UIAlertAction(title: "Delete", style: .default, handler: { (action) in
tableView.deselectRow(at: indexPath, animated: false)
self.tableView.reloadData()
print("Delete")
})
let cancelAction = UIAlertAction(title: "Cancel", style: .default, handler: { (action) in
tableView.deselectRow(at: indexPath, animated: false)
})
ac.addAction(detailAction)
ac.addAction(deleteAction)
ac.addAction(cancelAction)
self.present(ac, animated: true, completion: nil)
return
}
if post["status"] as! String == "accepted" {
let vc = messageViewController()
let posting = RquestInfoArray[indexPath.row]
let postId = posting["rquestId"] as! String
vc.hidesBottomBarWhenPushed = true
vc.postId = postId
self.navigationController?.pushViewController(vc, animated: true)
}
}
我假设您有一个Custom Cell类,其标签带有橙色背景(将其MyTableViewCell
)。
因此,您必须重写该单元格的setHighlighted(_:animated:)
函数,并将标签的背景保持为橙色。
override func setHighlighted(_ highlighted: Bool, animated: Bool) {
...
label.backgroundColor = <YourOrange>
}
您可能需要重写setSelected(_:animated:)
具体取决于您的代码。
您也可以只将单元格的UITableViewCellSelectionStyle
设置为UITableViewCellSelectionStyleNone
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.