user125972 user125972 - 2 months ago 13
iOS Question

Multiple UITableViewBugs with refreshControl

I have build a very simple demo app to illustrate the two bugs that I found when using UIViewController with tableView installed. These issues are not present if I use a standard UITableviewController.

Video to demonstrate the bug

project link to github


  1. Basically, when I pull to refresh slowly, I get this jump (approximately 30 points) downwards. I would also need to drag a fair bit down before the refresher is activated (half the screen approx). If I pull fast though, the issue is not there.

  2. If I implement hideNavigationBarOnSwipe and refreshControl at the same time, the section header because all ugly and out of place (Shown later in the video).



I was wondering, for this sort of bug, if I want to take a shot to see if Apple improved it, which of the following three options should I give it a go. (This project is built on xcode7.3, swift 2, IOS9.0


  1. Update from swift 2 to swift 3.

  2. Update Xcode from 7 to 8

  3. Build the app for a higher IOS version



----Full Code----

import UIKit

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

@IBOutlet weak var myTableView: UITableView!

var refreshControl: UIRefreshControl!

override func viewDidLoad() {
super.viewDidLoad()
myTableView.delegate = self
myTableView.dataSource = self

navigationController!.hidesBarsOnSwipe = true

refreshControl = UIRefreshControl()
refreshControl.addTarget(self, action: #selector(ViewController.refresh), forControlEvents: .ValueChanged)
myTableView.addSubview(refreshControl)
}

func refresh() {

}

@IBAction func stopRefreshingBtnPressed(sender: AnyObject) {
refreshControl.endRefreshing()
}

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 10
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("myCell", forIndexPath: indexPath)
cell.textLabel?.text = "section \(indexPath.section) row \(indexPath.row)"
return cell
}

func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 20
}

func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return "Section Header \(section)"
}
}

Answer
 override func viewDidLoad() {
    super.viewDidLoad()
    myTableView.delegate = self
    myTableView.dataSource = self
    navigationController!.hidesBarsOnSwipe = true

    refreshControl = UIRefreshControl()

    //Create an instance of a UITableViewController. This will host your UITableView.
     let tableController = UITableViewController()

    //Add tableController as a childViewController and set its tableView property to your UITableView.
    self.addChildViewController(tableController)
    tableController.tableView = myTableView
    tableController.refreshControl = self.refreshControl
}