App is freezing in 'peek and pop' implementation in iPhone 6s

Viewed 711

I have implemented peek and pop in my app and it works perfectly. But on continuously trying it for 7-8 times, the app freezes on peek view. The only option I have is to kill the app and re-run. Please let me know the reason for the freeze. I have used the following code for peek and pop in my project:

var isPresentedBy3Dtouch: Bool = false
var passedDetails:DetailModel!

func previewingContext(previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {

  guard let indexPath = tableView?.indexPathForRowAtPoint(location)
    else { return nil }

  guard let cell = tableView?.cellForRowAtIndexPath(indexPath)
    else { return nil }

  guard let detailViewController = self.storyboard?.instantiateViewControllerWithIdentifier("Navigation") as? UINavigationController
    else { return nil }

   (detailViewController.topViewController as! DetailViewController).passedDetails = self.customerLists[indexPath.row]
   (detailViewController.topViewController as! DetailViewController).isPresentedBy3Dtouch = true
   detailVC.preferredContentSize = CGSize(width: 0.0, height: 480.0)
    previewingContext.sourceRect = cell.frame
    return detailVC
}

func previewingContext(previewingContext: UIViewControllerPreviewing, commitViewController viewControllerToCommit :UIViewController) {
    showViewController(viewControllerToCommit, sender: self) 
}
3 Answers

I found another possible reason for this bug.

In the viewControllerForLocation I instantiated a view controller to show...

func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
    let vc = VCImageFullScreen.loadView()
    return vc
}

...but this ViewController had a wrong super call in its viewDidAppear:

    class VCImageFullScreen : UIViewController {
        override func viewDidAppear(_ animated: Bool) {
            super.viewWillAppear(animated)
            //BUG --> should be super.view**Did**Appear(animated)
            ...
        }
    }

After fixing this issue everything worked as expected.

Related