UITableView load more when scrolling to bottom like Facebook application

后端 未结 18 2182

I am developing an application that uses SQLite. I want to show a list of users (UITableView) using a paginating mechanism. Could any one please tell me how to load more dat

18条回答
  •  我在风中等你
    2020-11-27 09:40

    let threshold = 100.0 // threshold from bottom of tableView
    var isLoadingMore = false // flag
    
    
    func scrollViewDidScroll(scrollView: UIScrollView) {
        let contentOffset = scrollView.contentOffset.y
        let maximumOffset = scrollView.contentSize.height - scrollView.frame.size.height;
    
        if !isLoadingMore && (maximumOffset - contentOffset <= threshold) {
            // Get more data - API call
            self.isLoadingMore = true
    
            // Update UI
            dispatch_async(dispatch_get_main_queue()) {
                tableView.reloadData()
                self.isLoadingMore = false
            }
        }
      }
    

提交回复
热议问题