简体   繁体   中英

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? 滚动直到tableView结束时,执行多次

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
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM