繁体   English   中英

UITableviewCell附件视图无法更改

[英]UITableviewCell accessoryView can't be changed

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


    }

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

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

我认为您可能必须执行if currentlyExpanded { cellForRowAtIndex if currentlyExpanded {检查cellForRowAtIndex并仅在didSelectRowAtIndex调用self.tableView.reloadData

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

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

我不得不将其更改为:

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM