[英]tableViewCell image property reset when selected - swift
I do create a custom cell with 2 UIImageView
inside and a UILabel
this way: 我确实通过以下方式创建了一个自定义单元格,其中包含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
The attribut avatar is the UIImageView
I decided to round. 属性头像是我决定舍入的
UIImageView
。 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
. 选择是作为
UIImageView
的复选框。 My problem is when I select a cell, the cell.avatar loses his property meaning it goes back as a square form. 我的问题是,当我选择一个单元格时,cell.avatar会失去其属性,这意味着它会以正方形形式返回。 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. cell.avatar仍处于加载状态,我在
willSelectRowAtIndexPath
和didSelectRowAtIndexPath
尝试了cell.avatar.layer.cornerRadius = cell.avatar.frame.size.width / 2
,但没有成功。
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. 唯一可能是此问题的起因的事实是,我确实使用了确实在我的头像附近的复选框
UIImageView
。
我发现我的头像附近的复选框没有约束,由于某种随机原因,即使它不影响头像视图,也仍在重置头像视图的圆形属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.