ios - 下拉刷新不适用于空的 TableView

标签 ios swift uitableview uirefreshcontrol

当我清除数据源中的所有数据并重新加载 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/

相关文章:

ios - 无效更新: invalid number of sections in UITableView

iphone - 如何跟踪 TableView 单元格中按钮的索引路径?

ios - 标记生成 : What is VM: Dispatch continuations

ios - 自定义 UITableViewCell 不会导致任何错误,但也不会显示

ios - 如何从 iOS 模拟器获取 IPA 文件

Swift 或 iOS 中等效的 Javascript ArrayBuffer

ios - Xcode : Different behavior between swift Int and Objective-C int

ios - 来自 UIApplicationShortcutIcon 的 UIImage

ios - 在 Web View 中具有标签

ios - 如何使用快速代码在按钮单击中的自定义 UITableViewCell 中显示 UIAlertController?