我在iOS Swift应用程序中实现了一些UIPreviewActions。但是,这些操作执行segue事务,这些事务被忽略。我怎么能做到这一点?
有一个类似的问题,但在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 :(得分:0)
很抱歉迟到的回复,但我最近遇到了这个,所以发布答案以防其他人认为它有用......
在调用UIPreviewAction
中的处理程序时,视图控制器已从层次结构中删除,因此执行segues无效。相反,你应该做类似的事情:
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)
}