-1

My tableView uses prefetching to cache images and works perfectly when I start the app but once I close out of the app, sending it to the background (not fully shutting it down) and click the app again, the cached images are gone but because the tableView already prefetched these images prior to closing, the prefetch method is not being called on the indexPaths that were previously loaded.

Im looking for a method or logic I can code that would call the prefetching method again based off the current indexPath allowing the indexPaths that were previously loaded and then lost to be reloaded. any help would be great?

Dane
  • 45
  • 6

1 Answers1

0

When your app enters from background to foreground, in appDelegate file inside method

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

Now you can set up listeners in your UIViewControllers setup code :

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

inside your UIViewController create your custom method and check if thats get called implement your logic inside that method.

@objc func YOUR_METHOD_NAME() {
    print("notification method called")
}
Bhawin Ranpura
  • 129
  • 1
  • 8