prepareForSegue 未在偷看时被调用

prepareForSegue Not Being Called upon Peeking

我正在尝试实现对静态 Table 视图的 peek 和 pop 支持。我成功地让 peek 和 pop 实际工作,但是在单元格上偷看时没有调用 prepareForSegue。

//  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")

}

如有任何帮助,我们将不胜感激。

事实证明,只有在使用故事板设置 Peek 和 Pop 时才会调用 prepareForSegue。我把我的代码放在 MasterPreviewing.swift 中,现在一切似乎都很好!