【问题标题】:How can I detect when the user has scrolled all the way to the top on the TableViewController?如何检测用户何时一直滚动到 TableViewController 的顶部?
【发布时间】:2020-01-01 05:32:30
【问题描述】:

是否可以检测到用户何时用尽了 TableViewController 中的所有提要?

如果是这样,怎么做?

例如,当您向下滑动到第一个帖子时,您应该会收到一条错误消息,上面写着“您是最新的”。

【问题讨论】:

标签: swift


【解决方案1】:

您可以在tableView中添加刷新控件,并在刷新控件方法中检查数据是否更新。如果没有找到新记录,则显示您是最新的。

例如

var refreshControl = UIRefreshControl()

override func viewDidLoad() {
   super.viewDidLoad()

   refreshControl.attributedTitle = NSAttributedString(string: "Pull to refresh")
   refreshControl.addTarget(self, action: #selector(refresh(_:)), for: UIControl.Event.valueChanged)
   tableView.addSubview(refreshControl) // not required when using UITableViewController
}

@objc func refresh(sender:AnyObject) {
   // Code to refresh table view  
   // Check data is updated or not and the show alert from here
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-07
    • 2013-06-27
    • 2019-04-08
    • 1970-01-01
    • 2020-03-16
    • 1970-01-01
    相关资源
    最近更新 更多