2016-07-16 325 views
1

我在我的iOS Swift應用程序中實現了一些窺視UIPreviewActions。但是,這些行爲會執行被忽略的延期交易。我怎麼能做到這一點?3DTouch UIPreviewAction:performseguewithidentifier not working

有一個類似的問題,但在Objective-C:UIPreviewAction to Mail From Peek

override func previewActionItems() -> [UIPreviewActionItem] { 
    let performSegueAction = UIPreviewAction(title: "Go To View", style: .Default) { (action, viewController) -> Void in 
    self.performSegueWithIdentifier("segueID", sender: self) 
    } 
    return [performSegueAction] 
} 

回答

0

對不起已故的答覆,但最近張貼這樣的情況下,別人的答案就遇到了這個自己認爲有用...

當您調用UIPreviewAction中的處理程序時,視圖控制器已從層次結構中刪除,因此執行segse不起作用。相反,你應該這樣做:

class PreviewViewController: UIViewController { 

var performAction: (() -> Void)? 

override func previewActionItems() -> [UIPreviewActionItem] { 
    let performSegueAction = UIPreviewAction(title: "Go To View", style: .Default) { (action, viewController) -> Void in 
     self.performAction?() 
    } 
    return [performSegueAction] 
} 

而且在父控制器(您將從這裏啓動預覽):

class ParentViewController: UIViewController { 

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    if let vc = segue.destination as? PreviewViewController { 
     vc.handleAction = { 
      self.performSegueWithIdentifier("segueID", sender: self) 
     } 
    } 
    inject(toController: segue.destination) 
}