ios - UITableviewCell accessoryView 无法更改

标签 ios iphone swift uitableview uiaccessoryview

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

相关文章:

ios - 计算与地板的角度

ios - 使用 SpriteKit 呈现插页式广告会重新启动整个场景

iphone - Iphone 的 MMX 说明

ios - 如何允许用户每 "n"秒刷新一次表?

ios - 加载表格 View 时应用程序崩溃并出现错误 "Invalid update: invalid number of sections."

iphone - 如何停止在iPhone中执行线程

iphone - Android 的 viewDidLoad 和 viewDidAppear 等效

ios - 动画 UIView 离开屏幕然后从底部无休止地离开屏幕

ios - 我如何指示从 SKScene 使用 UIKit 创建的 View ?

swift - 具有多个部分以及单选按钮和复选框按钮的 TableView