选择单元格后,Swift tableView单元子视图会闪烁(消失,然后重新出现)

时间:2017-02-05 23:53:41

标签: ios swift uitableview

我有一个带有几个不同子视图的viewCell。其中一个是橙色背景的标签。现在,当我在tableview中选择单元格时,标签背景闪烁(消失,然后重新出现)到原来我看不出是什么导致了这个问题。

//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)
        }
    }

1 个答案:

答案 0 :(得分:0)

我假设您有一个Custom Cell类,其标签带有橙色背景(我们称之为MyTableViewCell)。

因此,您必须覆盖该单元格的setHighlighted(_:animated:)函数,并将标签的背景保持为橙色。

override func setHighlighted(_ highlighted: Bool, animated: Bool) {
    ...
    label.backgroundColor = <YourOrange>
}

您可能需要覆盖setSelected(_:animated:),具体取决于您的代码。

您也可以只设置单元格UITableViewCellSelectionStyle to UITableViewCellSelectionStyleNone

相关问题