首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UITableviewCell accessoryView不能更改

UITableviewCell accessoryView不能更改
EN

Stack Overflow用户
提问于 2015-07-22 10:07:08
回答 2查看 268关注 0票数 0

我需要将accessoryView更改为适当的UIImageView

代码语言:javascript
复制
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时,不能在此之后更改它(实际上,我可以更改视图指针,但在屏幕上没有看到任何更改)

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-07-22 10:31:42

我找到了解决办法。问题就在后面:

代码语言:javascript
复制
var cell = tableView(self.tableViewMain, cellForRowAtIndexPath: indexPath) as! ActivitySectionCell

我不得不把它改成:

代码语言:javascript
复制
var cell = tableViewMain.cellForRowAtIndexPath(indexPath) as! ActivitySectionCell

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

票数 1
EN

Stack Overflow用户

发布于 2015-07-22 10:13:52

我认为您可能需要在cellForRowAtIndex中进行cellForRowAtIndex检查,只需在didSelectRowAtIndex中调用self.tableView.reloadData即可。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31560066

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档