我试图为静态表视图实现查看和弹出支持。我成功地获得了窥视和弹出以实际工作,但是在窥视细胞时没有调用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")
}
任何帮助都将不胜感激。
答案 0 :(得分:0)
结果只有在使用故事板设置Peek和Pop时才会调用prepareForSegue。我把我的代码放在MasterPreviewing.swift
中,现在一切都好了!