[英]UITableviewCell accessoryView can't be changed
I need to change the accessoryView to proper UIImageView 我需要将附件视图更改为正确的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))
}
}
I checked in debug, sometimes I set "collapse" image, sometimes "edit" image, but after that I always see "edit" image in the cell. 我检查了调试,有时设置了“折叠”图像,有时设置了“编辑”图像,但是之后,我总是在单元格中看到“编辑”图像。
So when I set accessoryView at the very beginning , I can't change it after that (actually I can change the view pointer, but after that on the screen I don't see any changes) 因此,当我在开始时设置了附件视图时,此后就无法更改(实际上,我可以更改视图指针,但是在屏幕上之后,我看不到任何更改)
我认为您可能必须执行if currentlyExpanded {
cellForRowAtIndex
if currentlyExpanded {
检查cellForRowAtIndex
并仅在didSelectRowAtIndex
调用self.tableView.reloadData
。
I found the solution. 我找到了解决方案。 The problem was in the row:
问题出在行中:
var cell = tableView(self.tableViewMain, cellForRowAtIndexPath: indexPath) as! ActivitySectionCell
I had to change it to : 我不得不将其更改为:
var cell = tableViewMain.cellForRowAtIndexPath(indexPath) as! ActivitySectionCell
Because otherwise I will change not the current cell, but other returning cell 因为否则我将不更改当前单元格,而是其他返回单元格
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.