jefferyleo jefferyleo - 4 years ago 231
Swift Question

Scrolling the end of tableView ios swift

override func scrollViewDidScroll(scrollView: UIScrollView)
{
if (scrollView.contentOffset.y >= (scrollView.contentSize.height - scrollView.frame.size.height))
{
print("test")//loadMoreData()
}

}


In this code, I'm written to detect the tableView is scrolling until the end, then it will load more data, however it will execute many times as seen in the image of my console output, I just want execute one time after the end of tableView, how do I do that?
Execute many times once I scroll until the end of tableView

Answer Source

The simplest solution is a flag call you function only once on the base of the flag and change the value once call.But this is only works if you want to load more data only once.

if (scrollView.contentOffset.y >= (scrollView.contentSize.height - scrollView.frame.size.height))
    {
      if (!isLoaded)
         print("test")//loadMoreData()
      isLoaded = true
    }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download