gpt4 book ai didi

ios - 在 NSTimer 间隔上,UITableView.visibleCells 错误响应

转载 作者:行者123 更新时间:2023-11-29 01:15:56 24 4
gpt4 key购买 nike

我正在使用间隔为 1.1 秒的 NSTimer,计时器正确触发,但(大部分)在滚动 UITableView.visibleCells 时不更新响应,响应包含不可见的单元格。

下面是我的 Swift 代码

private func onApiResponse() {
_timer = NSTimer.scheduledTimerWithTimeInterval(1.1, target: self, selector: "myTimer", userInfo: nil, repeats: true)
}

后端 API 响应后的计时器

func myTimer() {
for cell in tableView.visibleCells {
if let indexPath = tableView.indexPathForCell(cell) {
// do something
}
}
}

最佳答案

这是对我的情况有效的修复。

为了使用 tableView.visibleCells 获取可见单元格,我使用 tableView.indexPathsForVisibleRowstableView.cellForRowAtIndexPath 获取索引路径列表,如下所示是示例代码:

if let paths = mode == 0 ? tvList.indexPathsForVisibleRows : tvGallery.indexPathsForVisibleRows {
for path in paths {
if let isNotNil = moProducts[path.row].data where moProducts[path.row].bidValid {
if let cell = (mode == 0 ? tvList.cellForRowAtIndexPath(path) : tvGallery.cellForRowAtIndexPath(path)) as? SubClassCell {
// do something here with the cell
}
}
}
}

关于ios - 在 NSTimer 间隔上,UITableView.visibleCells 错误响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35188601/

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