2016-08-18 83 views

回答

23

試試這個

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

感謝@ Anbu.Karthik找到。我很可能會這樣做。我非常害怕這樣的原始方法仍然需要在2016年使用,但它是如此。什麼阻止工程師引入「func scrollViewDidScrollToBottom」功能? –

+0

@TheMotherofJosephBeuys - 我不明白你的觀點,有什麼方法可用在iOS中'func scrollViewDidScrollToBottom「' –

+0

不要擔心@ Anbu.Karthik,我只是呻吟 –

16

斯威夫特3

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { 
    if indexPath.row + 1 == yourArray.count { 
     print("do something") 
    } 
} 
+1

該解決方案僅在有1個區段時纔有效,當有更多區段時,那麼需要累積左邊的行 – kjoelbro

+1

這似乎是對我最好的答案 –

+1

@kjoelbro您可以方便地獲得整個'indexPath'。您可以輕鬆地確定tableview的結尾位置 –