10

I am working on implementing state restoration into my app, however I have ran into an issue. I recently added 3D Touch support to the table view, and it worked perfectly every time except now that I have added state restoration. When the app restores the table view, applying pressure to the cells does nothing, as if the table view hasn't been registered for previewing.

I have this code in viewDidLoad:

override func viewDidLoad() {
    super.viewDidLoad()

    if #available(iOS 9.0, *) {
        if traitCollection.forceTouchCapability == UIForceTouchCapability.Available {
            registerForPreviewingWithDelegate(self, sourceView: view)
        }
    }
}

I tried moving it to viewDidAppear to see if it would help, but it didn't make a difference.

Any ideas?

user3746428
  • 11,047
  • 20
  • 81
  • 137

1 Answers1

4

Ok, I figured it out eventually. I had to move registerForPreviewingWithDelegate to viewWillAppear and I also had to add self. to the beginning.

user3746428
  • 11,047
  • 20
  • 81
  • 137