UIRefreshControl at the bottom of the UITableView iOS6?

前端 未结 8 2029
你的背包
你的背包 2020-12-01 06:27

Is it possibile add UIRefreshControl at the bottom of the UITableView? I would use it to load more data. Please, Any suggest?

8条回答
  •  渐次进展
    2020-12-01 07:06

    The following answer is in Xcode 8 and Swift 3.

    first declare

    var spinner = UIActivityIndicatorView()
    

    than in viewDidLoad method write the following code:

    spinner = UIActivityIndicatorView(activityIndicatorStyle: .whiteLarge)
    spinner.stopAnimating()
    spinner.hidesWhenStopped = true
    spinner.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: 60)
    tableView.tableFooterView = spinner
    

    now finally override the scrollViewDidEndDragging delegate method with following:

    override func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
            let offset = scrollView.contentOffset
            let bounds = scrollView.bounds
            let size = scrollView.contentSize
            let inset = scrollView.contentInset
    
            let y = offset.y + bounds.size.height - inset.bottom
            let h = size.height
    
            let reloadDistance = CGFloat(30.0)
            if y > h + reloadDistance {
                print("fetch more data")
                spinner.startAnimating()
            }
    }
    

提交回复
热议问题