简体   繁体   中英

tableViewCell image property reset when selected - swift

I do create a custom cell with 2 UIImageView inside and a UILabel this way:

        let ChildCellID = "ChildCell"
        if indexPath.section < 2 {
            var cell = SectionCell.loadOrDequeueWithTableView(tableView, reuseIdentifier: SectionCellID)

            if cell == nil {
                cell = SectionCell.viewFromNib()
            }
            cell.delegate = self as SectionCellDelegate
            cell.avatar?.loadAvatarURL(child.avatarUrl)
            cell.avatar.layer.cornerRadius = cell.avatar.frame.size.width / 2

The attribut avatar is the UIImageView I decided to round. When a cell is selected my code goes:

    func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? {
    let tableViewCell = tableView.cellForRowAtIndexPath(indexPath)
    if let cell : SectionCell = tableViewCell as? SectionCell {
        cell.selection = !cell.selection

    } else if let cell : ChildCell = tableViewCell as? ChildCell {
        cell.selection = !cell.selection
    }
    return indexPath
}

Selection is the checkbox as UIImageView . My problem is when I select a cell, the cell.avatar loses his property meaning it goes back as a square form. The cell.avatar is still loaded and I tried cell.avatar.layer.cornerRadius = cell.avatar.frame.size.width / 2 in the willSelectRowAtIndexPath and didSelectRowAtIndexPath but without success.

Am I missing anything that makes my avatar loses his rounded property ? The only thing that could possibly be the origin of this problem would be the fact that I do use the checkbox UIImageView which is really near my avatar.

我发现我的头像附近的复选框没有约束,由于某种随机原因,即使它不影响头像视图,也仍在重置头像视图的圆形属性。

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