Prefer Large Titles and RefreshControl not working well

后端 未结 11 2143
野性不改
野性不改 2020-12-29 05:09

I am using this tutorial to implement a pull-to-refresh behavior with the RefreshControl. I am using a Navigation Bar. When using normal titles eve

相关标签:
11条回答
  • 2020-12-29 05:56

    I'm having the same problem, and none of the other answers worked for me.

    I realised that changing the table view top constraint from the safe area to the superview fixed that strange spinning bug.

    Also, make sure the constant value for this constraint is 0

    0 讨论(0)
  • 2020-12-29 05:58

    The only solution that worked for me using XIBs was Bruno's one: https://stackoverflow.com/a/54629641/2178888

    However I did not want to use a XIB. I struggled a lot trying to make this work by code using AutoLayout.

    I finally found a solution that works:

        override func loadView() {
            super.loadView()
            let tableView = UITableView()
            //configure tableView
            self.view = tableView
        }
    
    0 讨论(0)
  • 2020-12-29 05:59

    Problem can be solved if add tableview or scroll view as root view in UIViewController hierarchy (like in UITableViewController)

    override func loadView() {
        view = customView
    }
    

    where customView is UITableView or UICollectionView

    0 讨论(0)
  • 2020-12-29 06:00

    At the end what worked for me was:

    • In order to fix the RefreshControl progress bar disappearing bug with large titles:

      self.extendedLayoutIncludesOpaqueBars = true
      
    • In order to fix the list offset after refreshcontrol.endRefreshing():

      let top = self.tableView.adjustedContentInset.top
      let y = self.refreshControl!.frame.maxY + top
      self.tableView.setContentOffset(CGPoint(x: 0, y: -y), animated:true)
      
    0 讨论(0)
  • 2020-12-29 06:02

    I've faced the same problem. Call refreshControl endRefreshing before calling further API.

    refreshControl.addTarget(controller, action: #selector(refreshData(_:)), for: .valueChanged)
    
    @objc func refreshData(_ refreshControl: UIRefreshControl) {
            refreshControl.endRefreshing()
            self.model.loadAPICall {
                self.tableView.reloadData()
            }
        }
    
    0 讨论(0)
提交回复
热议问题