【问题标题】:how to refetch data that has already been fetched如何重新获取已经获取的数据
【发布时间】:2019-09-03 04:03:01
【问题描述】:

我的 tableView 使用预取来缓存图像,并且在我启动应用程序时完美运行,但是一旦我关闭应用程序,将其发送到后台(未完全关闭它)并再次单击应用程序,缓存的图像就消失了但是由于 tableView 在关闭之前已经预取了这些图像,因此不会在先前加载的 indexPaths 上调用 prefetch 方法。

我正在寻找一种方法或逻辑,我可以编写代码,根据当前的 indexPath 再次调用预取方法,从而允许重新加载之前加载然后丢失的 indexPath。有什么帮助会很好吗?

【问题讨论】:

  • 你的问题到底是什么?它与缓存图像有关吗?或者别的什么

标签: swift xcode uitableview uicollectionview prefetch


【解决方案1】:

当你的应用从后台进入前台时,在appDelegate文件里面的方法

func applicationDidBecomeActive(_ application: UIApplication) {
    NotificationCenter.default.post(Notification.init(name: Notification.Name(rawValue: "appDidEnterForeground")))
}

现在您可以在 UIViewControllers 设置代码中设置监听器:

override func viewDidLoad() {
       NotificationCenter.default.addObserver(self,
                                           selector: #selector(self.YOUR_METHOD_NAME),
                                           name: NSNotification.Name(rawValue: "appDidEnterForeground"),
                                           object: nil)
}

在您的 UIViewController 中创建您的自定义方法并检查是否调用了在该方法中实现您的逻辑。

@objc func YOUR_METHOD_NAME() {
    print("notification method called")
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-26
    • 1970-01-01
    • 2013-04-21
    • 1970-01-01
    • 2013-10-18
    • 2020-07-04
    • 2012-06-09
    • 1970-01-01
    相关资源
    最近更新 更多