![](/img/trans.png)
[英]How to Change the image of UIButton when selected which is on tableVIewCell. in Swift 3
[英]tableViewCell image property reset when selected - swift
我確實通過以下方式創建了一個自定義單元格,其中包含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
和didSelectRowAtIndexPath
嘗試了cell.avatar.layer.cornerRadius = cell.avatar.frame.size.width / 2
,但沒有成功。
我是否錯過任何使我的化身失去其圓形財產的東西? 唯一可能是此問題的起因的事實是,我確實使用了確實在我的頭像附近的復選框UIImageView
。
我發現我的頭像附近的復選框沒有約束,由於某種隨機原因,即使它不影響頭像視圖,也仍在重置頭像視圖的圓形屬性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.