![](/img/trans.png)
[英]Animate the backgroundColor of a UITableViewCell with an accessoryView
[英]UITableviewCell accessoryView can't be changed
我需要將附件視圖更改為正確的UIImageView
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView .dequeueReusableCellWithIdentifier("ActivitySectionCell") as! ActivitySectionCell
var imageNameOfAccessory = expandedSections.containsIndex(indexPath.section) ? "collapse" : "edit"
cell.accessoryView = UIImageView(image: UIImage(named: imageNameOfAccessory))
return cell
}
func tableView(tableViewMethod: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableViewMethod.deselectRowAtIndexPath(indexPath, animated: true)
var cell = tableView(self.tableViewMain, cellForRowAtIndexPath: indexPath) as! ActivitySectionCell
if currentlyExpanded {
var imageNameOfAccessory = !currentlyExpanded ? "collapse" : "edit"
cell.accessoryView = UIImageView(image: UIImage(named: imageNameOfAccessory))
}
else {
var imageNameOfAccessory = !currentlyExpanded ? "collapse" : "edit"
cell.accessoryView = UIImageView(image: UIImage(named: imageNameOfAccessory))
}
}
我檢查了調試,有時設置了“折疊”圖像,有時設置了“編輯”圖像,但是之后,我總是在單元格中看到“編輯”圖像。
因此,當我在開始時設置了附件視圖時,此后就無法更改(實際上,我可以更改視圖指針,但是在屏幕上之后,我看不到任何更改)
我認為您可能必須執行if currentlyExpanded {
cellForRowAtIndex
if currentlyExpanded {
檢查cellForRowAtIndex
並僅在didSelectRowAtIndex
調用self.tableView.reloadData
。
我找到了解決方案。 問題出在行中:
var cell = tableView(self.tableViewMain, cellForRowAtIndexPath: indexPath) as! ActivitySectionCell
我不得不將其更改為:
var cell = tableViewMain.cellForRowAtIndexPath(indexPath) as! ActivitySectionCell
因為否則我將不更改當前單元格,而是其他返回單元格
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.