prepareForSegue不被人偷看

时间:2016-05-07 22:12:38

标签: ios swift 3dtouch

我试图为静态表视图实现查看和弹出支持。我成功地获得了窥视和弹出以实际工作,但是在窥视细胞时没有调用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")

}

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:0)

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