我需要将 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/