gpt4 book ai didi

ios - 3DTouch UIPreviewAction : performseguewithidentifier not working

转载 作者:行者123 更新时间:2023-11-28 08:33:14 24 4
gpt4 key购买 nike

我在我的 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]
}

最佳答案

抱歉回复晚了,但最近我自己遇到了这个问题,所以张贴答案以防其他人发现它有用...

在调用 UIPreviewAction 中的处理程序时, View Controller 已经从层次结构中删除,因此执行 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]
}

并且在父 Controller 中(您从中启动预览):

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)
}

关于ios - 3DTouch UIPreviewAction : performseguewithidentifier not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38408597/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com