0

I'm trying to implement peek and pop support for a static Table View. I was successful at getting peek and pop to actually work, but prepareForSegue is not being called when peeking on a cell.

//  MasterPreviewing.swift
import UIKit

extension ThemesViewController: UIViewControllerPreviewingDelegate {
func previewingContext(previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
    guard let viewController = self.storyboard?.instantiateViewControllerWithIdentifier("ThemesPreviewStoryboard") as? ThemePreviewViewController else { return nil }

    viewController.preferredContentSize = CGSize(width: 376, height: 668)

    return viewController
  }

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

-

// ThemesViewController.swift
import UIKit
override func viewDidLoad() {
    super.viewDidLoad()

    for cell in cells {
        if traitCollection.forceTouchCapability == .Available {
            self.registerForPreviewingWithDelegate(self, sourceView: cell)
        }
    }

}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    print("prepareForSegue called")

}

Any help would be appreciated.

Andrew
  • 63
  • 6
  • 1
    You aren't performing a segue, so why would `prepareForSegue` b called? – Paulw11 May 08 '16 at 00:23
  • Before I switched over to doing this programatically, I was enabling Peek and Pop directly from the storyboards. Turns out prepareForSegue is only called when you enable Peek and Pop through storyboards. @Paulw11 – Andrew May 08 '16 at 01:11
  • That's correct, because then you are using a peek segue – Paulw11 May 08 '16 at 03:02

1 Answers1

0

Turns out prepareForSegue is only called when setting up Peek and Pop using storyboards. I put my code in MasterPreviewing.swift, and all seems good now!

Andrew
  • 63
  • 6