gpt4 book ai didi

ios - UITableviewCell accessoryView 无法更改

转载 作者:行者123 更新时间:2023-11-28 13:10:20 27 4
gpt4 key购买 nike

我需要将 accessoryView 更改为正确的 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))
}


}

我检查了调试,有时我设置“折叠”图像,有时“编辑”图像,但之后我总是在单元格中看到“编辑”图像。

所以当我一开始就设置了 accessoryView 之后,我就不能再改变它了(实际上我可以改变 View 指针,但是之后在屏幕上我看不到任何变化)

最佳答案

我认为您可能需要执行 if currentlyExpanded { 检查 cellForRowAtIndex 并在 中调用 self.tableView.reloadData >didSelectRowAtIndex

关于ios - UITableviewCell accessoryView 无法更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31560066/

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