Reputation: 5247
When I clear all data from datasource and reload the tableView the pull-to-refresh is no more available. How can I enable pull-to-refresh even on an empty tableView?
override func viewDidLoad() {
super.viewDidLoad()
...
// Pull to refresh for iPhone
refreshControl?.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)
tableView.tableFooterView = UIView(frame: CGRectZero) // To remove separator line on empty cells
tableView.estimatedRowHeight = Constants.DetailTableView.estimatedRowHeight
tableView.rowHeight = UITableViewAutomaticDimension
setupRefreshControl()
}
private func setupRefreshControl() {
// If on iPhone, List becomes the pull-to-refresh handler and the delegate
if UIScreen.mainScreen().traitCollection.horizontalSizeClass == .Compact {
SyncService.shared.delegate = self
refreshControl?.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)
refreshControl?.tintColor = UIColor.whiteColor()
} else {
// Otherwise disable the refresh control in List
refreshControl = nil
}
}
Upvotes: 2
Views: 4090
Reputation: 824
In my case, I just need to enable bouncing:
self.collectionView.alwaysBounceVertical = YES;
default NO. if YES and bounces is YES, even if content is smaller than bounds, allow drag vertically
Upvotes: 14
Reputation: 5247
In the table refresh function I actually have code to display some 'empty table' view to remind the user the tableview is empty and this view was above the tableview's view, hence blocking the interaction. I fixed the view's layers and now it's working. So if you experience the issue in the question, just check whether some view does not overlap your tableview, which was my case here.
Upvotes: 3