下面的帖子仍然是檢測UITableView的實例何時滾動到底部[在Swift]中,還是被更改(如:改進後)的可接受方式?當UITableView已滾動到底部時檢測到
Problem detecting if UITableView has scrolled to the bottom
謝謝。
下面的帖子仍然是檢測UITableView的實例何時滾動到底部[在Swift]中,還是被更改(如:改進後)的可接受方式?當UITableView已滾動到底部時檢測到
Problem detecting if UITableView has scrolled to the bottom
謝謝。
試試這個
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let height = scrollView.frame.size.height
let contentYoffset = scrollView.contentOffset.y
let distanceFromBottom = scrollView.contentSize.height - contentYoffset
if distanceFromBottom < height {
print(" you reached end of the table")
}
}
,或者你可以用這種方式
if tableView.contentOffset.y >= (tableView.contentSize.height - tableView.frame.size.height) {
//you reached end of the table
}
斯威夫特3
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if indexPath.row + 1 == yourArray.count {
print("do something")
}
}
該解決方案僅在有1個區段時纔有效,當有更多區段時,那麼需要累積左邊的行 – kjoelbro
這似乎是對我最好的答案 –
@kjoelbro您可以方便地獲得整個'indexPath'。您可以輕鬆地確定tableview的結尾位置 –
感謝@ Anbu.Karthik找到。我很可能會這樣做。我非常害怕這樣的原始方法仍然需要在2016年使用,但它是如此。什麼阻止工程師引入「func scrollViewDidScrollToBottom」功能? –
@TheMotherofJosephBeuys - 我不明白你的觀點,有什麼方法可用在iOS中'func scrollViewDidScrollToBottom「' –
不要擔心@ Anbu.Karthik,我只是呻吟 –