我有一个隐藏字幕的UITableView,但是设置当有人选择一个单元格时,它会显示该单元格的字幕。这很好,除了点击任何单元格来显示它的字幕后,如果你向下滚动,你会发现每12个单元格都没有隐藏它们的字幕(以及它应该显示的那个)。下面是我在didSelectRowAtIndexPath中使用的代码:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
for cell in tableView.visibleCells() {
cell.detailTextLabel??.hidden = true
}
var cell = tableView.cellForRowAtIndexPath(indexPath)
cell?.detailTextLabel?.hidden = false
}我确信这与".visibleCells()“有关,因为每12个单元格大约是我的iPhone 6 Plus上可见表的高度。当我在模拟器的4s上运行它时,它大约每8个单元。但我不知道除了“visibleCells”还有什么办法?但这很奇怪,因为它是整个桌子-一直向下,每12个细胞显示它的副标题.
谢谢你的帮助
发布于 2015-03-07 23:15:22
UITableView重复使用细胞。因此,您单击的行的单元格(取消隐藏的字幕)可用于另一行。解决方案是在prepareForReuse子类中定义UITableViewCell ()方法(如果没有子类,则创建子类),然后在那里再次隐藏副标题。
发布于 2015-03-07 23:35:41
将dataSource的方法添加到控制器中。应该能正常工作。
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) {
var identifier = "cellIdentifier"
var cell = tableView. dequeueReusableCellWithIdentifier(identifier, forIndexPath: indexPath)
cell.detailTextLabel?.hidden = true
return cell
}https://stackoverflow.com/questions/28921145
复制相似问题