Just curious, as it doesn't immediately seem possible, but is there a sneaky way to leverage the new iOS 6 UIRefreshControl
class without using a UITableViewController
subclass?
I often use a UIViewController
with a UITableView
subview and conform to UITableViewDataSource
and UITableViewDelegate
rather than using a UITableViewController
outright.
What you would try is use container view inside ViewController you are using. you can define clean UITableViewController subclass with dedicated tableview and place that in the ViewController.
Keller's first suggestion causes a strange bug in iOS 7 where the inset of the table is increased after the view controller reappears. Changing to the second answer, using the uitableviewcontroller, fixed things for me.
For Swift 2.2 .
First make UIRefreshControl() .
In your viewDidLoad() method add:
And make refresh function
Try delaying the call to the refreshControl
-endRefresh
method by a fraction of a second after the tableView reloads its contents, either by using NSObject's-performSelector:withObject:afterDelay:
or GCD'sdispatch_after
.I created a category on UIRefreshControl for this:
I tested it and this also works on Collection Views. I've noticed that a delay as small as 0.01 seconds is enough:
Adding the refresh control as a subview creates an empty space above section headers.
Instead, I embedded a UITableViewController into my UIViewController, then changed my
tableView
property to point towards the embedded one, and viola! Minimal code changes. :-)Steps:
@IBOutlet weak var tableView: UITableView!
with the one from the newly embedded UITableViewController, as shown belowIt turns out you can use the following when you use a UIViewController with a UITableView subview and conform to UITableViewDataSource and UITableViewDelegate: