如何在 swift 中显示来自 UIPreviewAction 的视图控制器

how to show view controller from UIPreviewAction in swift

我是支持3D Touch的,我是这样做的,当用力拉cell时出现controller,然后用户拿起它,他看到了动作,当用户点击时会有一个按钮显示我想要的在它上面,控制器完全打开。我怎样才能显示这个控制器?

 @available(iOS 9.0, *)
override func previewActionItems() -> [UIPreviewActionItem] {
    let showAction = UIPreviewAction(title: "Show", style: .Default) { [weak self] (action: UIPreviewAction, vc: UIViewController) -> Void in
        guard let weakSelf = self else {
            return;
        }

        if let _popAction = weakSelf.popAction {
            _popAction()
        }
        self?.showViewController(vc, sender: nil)
        print("show city controller")
    }

    return [showAction]
}

我更改了代码

 @available(iOS 9.0, *)
override func previewActionItems() -> [UIPreviewActionItem] {
    let showAction = UIPreviewAction(title: "Show", style: .Default) { [weak self] (action: UIPreviewAction, vc: UIViewController) -> Void in
        guard let weakSelf = self else {
            return;
        }

        if let _popAction = weakSelf.popAction {
            _popAction()
        }
        self?.showViewController(vc, sender: nil)
        print("show city controller")
    }
    let cityController = CityController() 
    cityController.showPreviewController()
    return [showAction]
}