gpt4 book ai didi

ios - 如何根据滑出菜单导航到不同的 View Controller

转载 作者:可可西里 更新时间:2023-11-01 00:51:31 25 4
gpt4 key购买 nike

我是 Swift 的新手,现在已经尝试了很多个小时。

这是我的应用程序的样子:

enter image description here

理想情况下,我希望他们单击​​此弹出菜单中的一个选项,将他们带到另一个 View 。现在,我在 QuotesTimelineViewController 上,但说我想单击书签按钮,然后我想转到 SavedQuotesViewController。

这是我的 Storyboard的样子: enter image description here

QuotesViewController 中嵌入了一个 NavigationController。当您单击菜单按钮时,它会转到模态显示的 NavigationSideController。现在我不知道如何为我接下来要完成的事情做 segues。

这是我的 NavigationSideController 代码,所以现在当您单击 navigationsidebar 中的图标时会发生什么,它会关闭该动画并且 navigationsidebar 会消失。也许你可以看到所有被注释掉的代码。

enter image description here

这是来自 QuotesTimelineViewController 的一些相关代码(我认为):

enter image description here

但是我可能遗漏了一些东西,所以如果你想查看我的整个存储库,它就在这里:https://github.com/mayaah/ios-decal-proj4

任何指导都会很有帮助!最后,我希望每当我单击导航栏中的图标时,都会打开与该图标对应的 View Controller 。到目前为止,我取得的最大进展是出现了窗口层次结构错误!我猜是因为当我点击一个图标时,QuotesTimelineViewController 不在堆栈顶部或其他我不知道的东西。

最佳答案

我可以在这里提出两种解决方案

  1. 使用侧边菜单第三方库。

There are lot of things to take care of while creating a app sidemenu including nested heirarchy/rotations, shadows etc. The thirdparty libraries will take care of them easily and are well testedcode. You can choose the one you like from cocoacontrols

  1. 使用导航 Controller 并在表选择上更改事件 VC

    基本思想是在您的应用委托(delegate)中创建一个新的 navigationController 并创建所有不同类型的入口点。因此,在您的应用委托(delegate)中,声明一个新的 UINavigationController 变量。

您不会在此方法中使用 Storyboard initialVC。在 didFinishLaunching app delegate 方法

var navController:UINavigationController!

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
let storyboard = UIStoryboard(name: "Main", bundle: nil)
// make sure to set storyboard id in storyboard for these VC
let startingVC = storyboard.instantiateViewControllerWithIdentifier("QuotesTimeLine");
navController = UINavigationController(rootViewController: startingVC)
self.window!.rootViewController = navController
return true
}

然后在侧边菜单中,用新的 VC 更新 navController 的 viewController

 func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
// make sure to set storyboard id in storyboard for these VC
let startingVC = storyboard.instantiateViewControllerWithIdentifier("NewVC");
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.navController.viewControllers = [startingVC]
dismissViewControllerAnimated(true, completion: nil)
}

这仍然很粗略,但给出了管理层次结构所需的概念。如果需要任何说明,请告诉我。

关于ios - 如何根据滑出菜单导航到不同的 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36950237/

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