Search code examples
iosswiftswift2ios93dtouch

how to show view controller from UIPreviewAction in swift


I do support 3D Touch, I did so that when using strong pulled the cell appeared controller and then the user picked it up, he was shown the action, there will be a button to show I want when the user clicks on it, the controller fully opens. How can I show this 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]
}

Solution

  • I changed code

     @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]
    }