Load More After Coming to Bottom of UITableView

后端 未结 2 1353
情书的邮戳
情书的邮戳 2021-01-31 06:39

For my app I am using a \"load more at bottom\" property as below. It works fine actually; the only problem is that when a user reaches the buttom, while the load more function

2条回答
  •  渐次进展
    2021-01-31 07:20

  • Swift 3 , Xcode 8

  • func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        let lastElement = dataSource.count - 1
        if !loadingData && indexPath.row == lastElement {
            spinner.startAnimating()
            loadingData = true
            loadMoreData()
        }
    }
    

    as per @vacawama async call in swift 3:-

    func loadMoreData() {
        DispatchQueue.global(qos: .background).async {
            // this runs on the background queue
            // here the query starts to add new 10 rows of data to arrays
            DispatchQueue.main.async {
                 // this runs on the main queue
                    self.spinner.stopAnimating()
                    self.loadingData = false
    
            }
        }
    }
    

提交回复
热议问题