选择后自定义UITableViewCell更改?

时间:2016-01-08 07:06:41

标签: ios swift uitableview nib custom-cell

我的自定义UITableViewCell DayOfWeekTableViewCell正在显示一些奇怪的行为as you can see here.

我尝试通过在DayOfWeekTableViewCell

中添加以下行来解决此问题
class DayOfWeekTableViewCell: UITableViewCell {

    @IBOutlet weak var dayOfWeek: UILabel!
    @IBOutlet weak var totalAmountSpent: UILabel!

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code

        //Added these lines
        let colorView = UIView()
        colorView.backgroundColor = UIColor.clearColor()
        UITableViewCell.appearance().selectedBackgroundView  = colorView
    }

    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        // Configure the view for the selected state
    }

}

但现在我的应用就像this一样。我只是希望单元格在选择时看起来一样,不会被某个矩形斑点覆盖。

对此的任何帮助将不胜感激!

2 个答案:

答案 0 :(得分:1)

cell.selectionStyle = UITableViewCellSelectionStyleNone;将解决您的问题。我不知道它在swift上会是什么样子,所以只需将其发布在目标c中。祝你好运。

答案 1 :(得分:0)

如果您想要在选择时未更改单元格的行为,则可以在DayOfWeekTableViewCell类中添加以下方法。它只是确保每个单元格的选择样式为.None

override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
    super.init(style: style, reuseIdentifier: reuseIdentifier)
    self.selectionStyle = .None
}
相关问题