0

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


    }

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

所以当我一开始设置附件视图时,之后就无法更改(实际上我可以更改视图指针,但之后在屏幕上我看不到任何更改)

4

2 回答 2

1

我想你可能需要if currentlyExpanded {办理登机手续,cellForRowAtIndex然后打电话self.tableView.reloadDatadidSelectRowAtIndex.

于 2015-07-22T10:13:52.297 回答
1

我找到了解决方案。问题出在行中:

var cell = tableView(self.tableViewMain, cellForRowAtIndexPath: indexPath) as! ActivitySectionCell

我不得不将其更改为:

var cell = tableViewMain.cellForRowAtIndexPath(indexPath) as! ActivitySectionCell

因为否则我将不会更改当前单元格,而是其他返回的单元格

于 2015-07-22T10:31:42.933 回答