swift - uitableViewCell 图像属性在选择时重置 - swift

标签 swift uitableview uiimageview

我确实创建了一个自定义单元格,其中包含 2 个 UIImageView 和一个 UILabel,如下所示:

        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

属性头像是我决定舍入的UIImageView。当选择一个单元格时,我的代码将变为:

    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
}

选择是 UIImageView 的复选框。我的问题是,当我选择一个单元格时,cell.avatar 会失去他的属性,这意味着它会以方形形式返回。 cell.avatar 仍然加载,我在 willSelectRowAtIndexPath 中尝试了 cell.avatar.layer.cornerRadius = cell.avatar.frame.size.width/2 didSelectRowAtIndexPath 但没有成功。

我是否遗漏了任何使我的头像失去其圆形属性的东西? 唯一可能导致此问题的原因是我确实使用了非常靠近我的头像的复选框 UIImageView

最佳答案

我发现我头像附近的复选框缺少约束,由于某种随机原因,即使它没有影响头像 View ,也会重置头像 View 的圆角属性。

关于swift - uitableViewCell 图像属性在选择时重置 - swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37408011/

相关文章:

xcode - Swift:CoreData 库中的断点

iphone - UITableView 滚动时应该超出其框架

ios - 像使用 UIBarButtonItem 一样给 UIImage 着色

swift - '(字符串,AnyObject )' is not convertible to ' [字符串 : AnyObject]'

ios - Alamofire 4 文件上传参数问题

ios7 自动布局 tableViewCell

ios - 检查数组的当前索引是什么对象

ios - 使用 UIPanGestureRecognizer 复制 UIImageView

swift - 如何关闭应用程序崩溃时出现的系统对话框?

ios - 使用 AKPickerView 保存选择