gpt4 book ai didi

ios - 我如何转至与当前 Controller 共享同一根 Controller 的另一个 viewController?

转载 作者:行者123 更新时间:2023-11-28 07:48:38 26 4
gpt4 key购买 nike

我有 3 个 viewControllers:A、B 和 C。
A 有到 B 的转场,A 也有到 C 的转场。

如果我目前在 C 区,我该如何转至 B 区?

Note; I need to keep A active because once I'm in B, I need to be able to unwind back to A.

如果我可以从 C 展开到 A,然后在不显示 A 的情况下推送到 B,那么以下解决方案会很好,但我无法让它工作,而且没有人提供解决方案。

Chain two segues to look like one

Note; I'm not using a UINavigationController. I've tried simply pushing from C to B but then I'm not able to deallocate C. Calling unwind on C at any point during this process gives weird behaviour where A might appear on screen at some point.

有没有人能解决这个问题?

最佳答案

有很多方法可以完成您想要的。

我会做一些非常简单的事情:那就是添加一个unwind segue(上面解释了如何添加一个)以退出到第一个 A vc,并添加一个custom segue(无论是哪一个)介于 B 和 C(您只需使用 Storyboard创建)之间。

你从 A 开始,然后:

  • 如果你去 B,你可以使用 self.dismiss 返回,你使用你的退出 segue。
  • 如果你去C,你可以原路返回A,也可以去B。
  • 一旦您进入 B(从:A 到 C,C 到 B),您可以使用 self.dismiss 返回到 C,或者您可以使用 exit segue 返回到 A。

要添加un unwind segue,您必须向您的第一个类型的VC 添加一个函数:

@IBAction func unwindToA(segue: UIStoryboardSegue)

然后,当您在 B View Controller 上创建 segue 时(使用 control+drag),在 Storyboard中,开始从 VC 图标(在屏幕顶部)拖动到退出图标。然后,您会看到出现一个新的 segue,名为“unwindToA”,它将带您回到您的第一个 VC:A。

You can see theses icons here (on the top of the screen)

要创建从 B 到 C 的转场,您可以通过 control+从 Storyboard 中的第一个 VC 拖动到第二个 VC 来完成,然后选择您喜欢的类型(或者如果提供的类型没有,您可以创建自定义转场符合您的期望)。

关于ios - 我如何转至与当前 Controller 共享同一根 Controller 的另一个 viewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50286660/

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