gpt4 book ai didi

ios - 识别 UITableView 中的最后一个和第一个单元格

转载 作者:行者123 更新时间:2023-11-28 10:24:03 26 4
gpt4 key购买 nike

我有一个简单的表格 View 。我希望第一行和最后一行有一张特殊的图片来显示一行的开头和结尾。但是,我得到了错误的标识。表格 View 认为中间的单元格是末端单元格。我相信 IOS 正在缓存行并在需要时加载它们,因为当我上下滚动一些箭头时会改变图片(加载后它们应该是静态的)。还有 documentation says here知道如何解决这个问题并识别最后一行和第一行而不考虑缓存吗? (顺便说一句,位置是用于加载单元格的箭头,数组的第一个和最后一个位置是特殊图片应该在的位置)。

table view image

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
var stop = locations[indexPath.row]

var cell = tableView.dequeueReusableCellWithIdentifier("Cell") as! CustomRouteViewCell

cell.locationTitle.text = "\(stop)"

cell.downTime.text = BusRoute.getRecentDepartures(stop, direction: direction, name: name)

println(indexPath.row)

cell.indexRow = indexPath.row




if(cell.indexRow == 0)
{
cell.downImage.image = UIImage(named: "beginningRoute.png")
}
else if(cell.indexRow == locations.count - 1)
{
cell.downImage.image = UIImage(named: "endRoute.png")
}

return cell
}

最佳答案

问题可能不是您错误地识别了第一个和最后一个单元格(只要您的 UITableView 中只有一个部分,这看起来就没问题)。问题可能在于重复使用单元格:您没有将单元格的 downImage.image 设置为 nil,并且该单元格之前可能是第一个或最后一个单元格。

尝试以下操作:

switch indexPath.row {
case 0:
cell.downImage.image = UIImage(named: "beginningRoute.png")

case self.tableView(tableView, numberOfRowsInSection: 0) - 1:
cell.downImage.image = UIImage(named: "endRoute.png")

default:
cell.downImage.image = nil
}

关于ios - 识别 UITableView 中的最后一个和第一个单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30157550/

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