gpt4 book ai didi

ios - UITableView:突出显示最后一个单元格,但其他单元格也会突出显示

转载 作者:搜寻专家 更新时间:2023-11-01 06:39:31 24 4
gpt4 key购买 nike

我将 UITableView 用作滑动菜单,作为 SWRevealViewController 的一部分。

我想选择 UITableView 中的最后一个单元格并实现以下内容:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let customCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! IGAWindAloftMenuTableViewCell

...


let sectionsAmount = tableView.numberOfSections
let rowsAmount = tableView.numberOfRowsInSection(indexPath.section)

if (indexPath.section == sectionsAmount - 1 && indexPath.row == rowsAmount - 1)
{
customCell.backgroundColor = UIColor.yellowColor()
}

return customCell
}

当我一直向下滚动时,它起作用了——最后一个单元格被突出显示。但是,当我上下滚动时,表格中间的其他单元格也会突出显示。

有什么办法可以避免吗?

谢谢!

最佳答案

您必须撤销在 if 分支中对所有其他单元格所做的更改:

if (indexPath.section == sectionsAmount - 1 && indexPath.row == rowsAmount - 1) {
customCell.backgroundColor = UIColor.yellowColor()
} else {
customCell.backgroundColor = UIColor.whiteColor() // or whatever color
}

产生不良副作用的原因是细胞的重复使用。创建一个单元格,然后将其用作最后一个单元格,然后移出屏幕并在其他地方重复使用。它仍然包含更改后的颜色信息,但已不在相应位置。

关于ios - UITableView:突出显示最后一个单元格,但其他单元格也会突出显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37239523/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com