gpt4 book ai didi

尝试在另一个 Storyboard中打开时 iOS SideMenu 崩溃

转载 作者:行者123 更新时间:2023-11-28 06:27:01 26 4
gpt4 key购买 nike

我对 iOS 和 Swift 没有什么经验,我正在尝试创建一个 SlideOut 菜单,或在 Android 上调用的 NavigationDrawer。到目前为止,我正在使用这个 library (JonkyKong 的 SideMenu)因为它很容易定制并且如 GitHub 上的自述文件中所述,它可以在所有屏幕上全局使用。

这是我的问题:在我的菜单 tableViewController 上,我有两个 storyboard segues,一个到主 Storyboard,一个到第二个 Storyboard。如果我切换到第二个 Storyboard,当我尝试打开菜单时,应用程序崩溃并出现以下错误:Application tried to present modally an active controller

我做的菜单设置如下

在我的 AppDelegate.swift 文件中,我在 didFinishLaunchingWithOptions 函数上写了这个:

 var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

// Override point for customization after application launch.

// I've placed the menu ViewController on it's own storyboard, so I load it here to be used in the next line
let navDrawerStoryBoard = UIStoryboard.init(name: "NavDrawer", bundle: nil)

// Loads the menu
SideMenuManager.menuLeftNavigationController = navDrawerStoryBoard.instantiateViewController(withIdentifier: "LeftMenuNavigationController") as? UISideMenuNavigationController

// Here I'm setting a gesture recognizer to show the menu
SideMenuManager.menuAddScreenEdgePanGesturesToPresent(toView: window!)

return true

}

我还将我的项目上传到 GitHub 以备不时之需:sideMenuTest

感谢您的帮助。

最佳答案

您会遇到主要异常,因为您在已经打开的菜单上以模态方式呈现第二个 View 。

SideMenu 在所有 View 中共享一个菜单实例,因此如果菜单已经在模态第二个 View 下方打开,再次打开它会导致您看到异常。

上述问题的解决方案是在 Storyboard中使用“Show”segue 类型而不是模态类型: Show instead of modal

但是,在完成显示之后,您还需要将初始 View 嵌入到 NavigationController 中: Embed in nav

接下来,假设您希望它看起来保持不变,请隐藏导航栏: enter image description here

最后*,如果你想让导航顺利回到第一个屏幕,你会想在推送时跳过导航 Controller 。在 NavDrawer Storyboard中,将 ID 添加到 Storyboard引用: enter image description here

并添加与相应 Controller 的 Storyboard ID 相同的 ID: enter image description here

* 在我的测试中,我必须删除到第一个屏幕的 segue 并重新创建它才能正常工作。

关于尝试在另一个 Storyboard中打开时 iOS SideMenu 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41575769/

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