Swift 到达UITableView的末尾时加载更多
我试图在表视图中实现加载更多功能。我读过一篇文章,说代码将进入Swift 到达UITableView的末尾时加载更多,swift,uitableview,Swift,Uitableview,我试图在表视图中实现加载更多功能。我读过一篇文章,说代码将进入cellForRowAtfunc的内部,但这不起作用 我在这个特定的ViewController中有两个UITableView。在这之前一切都很顺利 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { if (tableView == userSearchesTableView)
cellForRowAt
func的内部,但这不起作用
我在这个特定的ViewController中有两个UITableView。在这之前一切都很顺利
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if (tableView == userSearchesTableView) {
if let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as? CellBasicItemInfo {
cell.isUserInteractionEnabled = true
let responseItems = userRecentSearches[indexPath.row]
cell.configureCell(item: responseItems)
cell.setNeedsLayout()
return cell
} else {
return CellBasicItemInfo()
}
} else {
if let cell = tableView.dequeueReusableCell(withIdentifier: "itemCell", for: indexPath) as? CellItems {
cell.isUserInteractionEnabled = true
let responseItems = resultsModelArray[indexPath.row]
cell.configureCell(item: responseItems)
cell.setNeedsLayout()
if (indexPath.row == self.resultsModelArray.count) {
print("REACHED THE BOTTOM") // does not print
}
return cell
} else {
return CellItems()
}
}
}
是否有其他或更好的方法来处理此功能
根据评论(不起作用)
更新
添加follow对我很有用
...
if (indexPath.row == self.userRecentSearches.count - 2) {
print("REACHED THE BOTTOM RECENT")
}
...
我真的不明白这个问题,是要延迟加载tableView,还是要区分两个表视图处理程序?很抱歉@AvivFrenkel出现了混淆。我有两个表视图,这就是为什么我的函数看起来如此。我想“延迟加载”这个“itemCell”。当我到达底部时,我将调用一个函数来加载项。好的,那么您需要做的是实现tableViewDelegate“willDisplay cell at”,并在其中检查您是否位于最后一个或倒数第二个单元格,如果您正在调用API调用,它将从您的服务器提供更多数据并更新tableView数据请参见上面的我的评论,这对我不起作用@AvivFrenkel谢谢@AvivFrenkel,我知道了。非常感谢。如果你想把它作为一个答案,我会接受它。
...
if (indexPath.row == self.userRecentSearches.count - 2) {
print("REACHED THE BOTTOM RECENT")
}
...