gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 13:24:16 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com