我确实创建了一个自定义单元格,其中包含 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/