我需要将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时,不能在此之后更改它(实际上,我可以更改视图指针,但在屏幕上没有看到任何更改)
发布于 2015-07-22 10:31:42
我找到了解决办法。问题就在后面:
var cell = tableView(self.tableViewMain, cellForRowAtIndexPath: indexPath) as! ActivitySectionCell我不得不把它改成:
var cell = tableViewMain.cellForRowAtIndexPath(indexPath) as! ActivitySectionCell因为否则,我将不更改当前单元格,而是更改其他返回单元格。
发布于 2015-07-22 10:13:52
我认为您可能需要在cellForRowAtIndex中进行cellForRowAtIndex检查,只需在didSelectRowAtIndex中调用self.tableView.reloadData即可。
https://stackoverflow.com/questions/31560066
复制相似问题