简体   繁体   中英

Custom UITableViewCell change when selected?

My custom UITableViewCell DayOfWeekTableViewCell is displaying some odd behavior as you can see here.

I tried to fix it by adding the following lines to my DayOfWeekTableViewCell class

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
    }

}

But now my app behaves like this . I just want the cell to look the same when I select it, not be covered up by some rectangular blob.

Any help on this would be greatly appreciated!

cell.selectionStyle = UITableViewCellSelectionStyleNone; will solve your problem. I don't know what it will look like on swift, so just post it in objective c. Good luck.

If you want the behaviour where a cell is not changed when selected, you can add following method in your DayOfWeekTableViewCell class. It just make sure that selection style of every cell is .None

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM