关闭发件人视图控制器后执行segue

编程入门 行业动态 更新时间:2024-10-23 11:20:40
本文介绍了关闭发件人视图控制器后执行segue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

基本上,我在滑出菜单中有一个按钮(它是它自己的视图控制器,覆盖了Origin屏幕的一部分,我们称它为Menu),当按下该按钮时,它会与另一个菜单执行模态搜索控制器,例如Destination.

Basically, I have a button in a slide-out menu (which is its own view controller that covers part of the Origin screen, let's call it Menu) that, when pressed, performs a modal segue to another controller, let's say Destination.

是否可以通过按下Menu中的按钮(转到Destination),将Menu退回到Origin,然后选择Destination?

Is there any way that upon pressing the button in Menu (to go to Destination), that I can dismiss Menu back to Origin, and THEN segue to Destination?

听起来很傻,但这是我以前见过的应用程序所做的事情.在我的情况下,要这样做的原因是,当我在Destination上按完成"时,它将控制器退回到Menu,而当我希望将其退回到Origin时.我不能只是从Destination回到Origin进行搜索.

It sounds silly but it's something that I think I've seen apps do before. In my case, the reason for wanting to do this is that once I press "Done" on Destination, it dismisses that controller back to Menu, when I want it to just dismiss back to Origin. I can't just perform a segue back to Origin from Destination.

代码:

这是我从Origin打开Menu的方式:

let interactor = Interactor() @IBAction func openMenu(_ sender: AnyObject) { performSegue(withIdentifier: "openMenu", sender: nil) } @IBAction func edgePanGesture(sender: UIScreenEdgePanGestureRecognizer) { let translation = sender.translation(in: view) let progress = MenuHelper.calculateProgress(translationInView: translation, viewBounds: view.bounds, direction: .Right) MenuHelper.mapGestureStateToInteractor( gestureState: sender.state, progress: progress, interactor: interactor){ self.performSegue(withIdentifier: "openMenu", sender: nil) } } override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if let destinationViewController = segue.destination as? MenuViewController { destinationViewController.transitioningDelegate = self destinationViewController.interactor = interactor destinationViewController.currentRoomID = self.currentRoomID } }

这是我目前从Menu到Destination的prepareForSegue,没什么好看的:

This is my prepareForSegue from Menu to Destination currently, nothing fancy:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { super.prepare(for: segue, sender: sender) let inviteVC = segue.destination as! InviteVipViewController inviteVC.currentRoomID = self.currentRoomID }

最后解散Destination只是一个简单的

And finally to dismiss Destination is just a simple

@IBAction func cancelButtonPressed(_ sender: Any) { self.dismiss(animated: true, completion: nil) }

我看到了这个问题,基本上是我要尝试的问题,但不幸的是没有答案:解散模式迅捷后执行segue

I saw this question which is basically what I'm trying to do but there was no answer unfortunately: Performing segue after dismissing modal swift

抱歉,这听起来令人困惑,但是如果有人知道我在说什么,并且可以让我知道如何设置segues/prepareForSegue使其起作用,那么任何输入都会受到赞赏!

Sorry if this sounds confusing, but if anyone knows what I'm talking about and can let me know how I can set up the segues/prepareForSegues to make it work, any input would be appreciated!

推荐答案

基于对此答案,以下方法应该起作用:

Based on a modification to this answer, the following should work:

在情节提要中,删除通过单击菜单按钮触发的segue,然后转到Destination.

In your storyboard, remove the segue that is triggered by tapping your menu button and goes to Destination.

创建一个新的序列,该序列从Origin视图控制器到Destination视图控制器.此任务将手动执行.

Create a new segue that goes from the Origin view controller to Destination view controller. This segue is going to be manually performed.

在菜单"中选择目标"选项后,让菜单自行关闭,然后在Origin上执行目标"序列,如下所示:

When your Destination option is selected in Menu, have Menu dismiss itself and then perform the Destination segue on Origin, like this:

// This code goes in Menu, and you should call it when // the menu button is tapped. // // presentingViewController is Origin weak var pvc = self.presentingViewController self.dismiss(animated: true) { // Menu has been dismissed, but before it is destroyed // it calls performSegue on Origin pvc?.performSegue(withIdentifier: "openDestination", sender: nil) }

关闭目的地"后,您应该会看到起源",而根本不会看到菜单".

When Destination is dismissed, you should see Origin, without seeing Menu at all.

我在一个示例应用程序中对此进行了测试,其中菜单"不是滑出菜单,而是完整的模态视图控制器,并且对我有用.

I tested this in a sample app where "Menu" was not a slide out, but a full modal view controller, and it worked for me.

编辑:在使用@KingTim进行故障排除时,他发现我们需要将Segue从UINavigationController(而不是Origin)连接到Destination.这是因为Origin在导航控制器内部.发现之后,它就起作用了.

While troubleshooting with @KingTim, he found that we needed to wire the segue from the UINavigationController, not Origin, to the Destination. This is because Origin is inside a navigation controller. After that discovery, it worked.

更多推荐

关闭发件人视图控制器后执行segue

本文发布于:2023-11-25 17:46:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630723.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发件人   视图   控制器   segue

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!