SplitViewController:如何替换辅助视图而不是推出新视图?

发布于 2025-02-09 15:43:23 字数 447 浏览 3 评论 0原文

如下所示,我有一个简单的故事板。顺时针从拆分视图控制器中顺时针旋转,我们有导航控制器,一个“主题选择器”和一个小游戏。主题选择器中的所有按钮都可以看到游戏中的所有按钮,告诉它要使用的颜色等。 所有这些都均为“显示细节(例如替换)”,而不是“ show(例如push)”。 我希望这些按钮可以用新的游戏视图替换游戏视图,但它会在旧游戏的顶部创建新的游戏视图,因此,如果您按下新的游戏视图一。我认为“显示细节”的重点是替换而不是添加。我在那里误会了什么,我该如何替换?

欢呼!

I have a simple storyboard as shown below. Clockwise from the split view controller we have the navigation controller, a "theme chooser" and a little game. All of the buttons in the theme chooser view segue to the game, telling it what colours to use etc. All of these segues are of type "Show Detail (e.g. replace)", not "Show (e.g. push)". I want the buttons to replace the game view with a new game view, but instead it creates the new game view on top of the old one, so if you press back on the new one, it goes back to the old one. I thought the point of "show detail" was to replace rather than add. What am I misunderstanding there and how do I get it to replace?

enter image description here

Cheers!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

耳钉梦 2025-02-16 15:43:23

我弄清楚了!

由于某些iOS更新,您需要将详细信息嵌入到导航视图中;即,

“

所以,我更改了准备代码的segue从:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "Choose Theme" {
        if let themeName = (sender as? UIButton)?.currentTitle, let theme = themes[themeName] {
            if let cvc = segue.destination as? ConcentrationViewController {
             cvc.theme = theme
            }
        }
    }
}

到现在

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "Choose Theme" {
        if let themeName = (sender as? UIButton)?.currentTitle, let theme = themes[themeName] {
            if let navigationController = segue.destination as? UINavigationController,
               let cvc = navigationController.topViewController as? ConcentrationViewController {
                cvc.theme = theme
            }
        }
    }
}

,现在起作用。

I figured it out!

Since some iOS update, you need to embed your detail view in a navigation view; i.e.,

storyboard

So, I changed my segue preparing code from:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "Choose Theme" {
        if let themeName = (sender as? UIButton)?.currentTitle, let theme = themes[themeName] {
            if let cvc = segue.destination as? ConcentrationViewController {
             cvc.theme = theme
            }
        }
    }
}

to

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "Choose Theme" {
        if let themeName = (sender as? UIButton)?.currentTitle, let theme = themes[themeName] {
            if let navigationController = segue.destination as? UINavigationController,
               let cvc = navigationController.topViewController as? ConcentrationViewController {
                cvc.theme = theme
            }
        }
    }
}

And now it works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文