Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issues with 3D Touch and state restoration

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?

like image 430
user3746428 Avatar asked Sep 28 '15 14:09

user3746428


1 Answers

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

like image 108
user3746428 Avatar answered Oct 09 '22 22:10

user3746428