当我清除数据源中的所有数据并重新加载 tableView 时,下拉刷新不再可用。如何在空 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
}
}
最佳答案
在我的例子中,我只需要启用弹跳:
self.collectionView.alwaysBounceVertical = YES;
default NO. if YES and bounces is YES, even if content is smaller than bounds, allow drag vertically
关于ios - 下拉刷新不适用于空的 TableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34810132/