在不使用导航控制器或以模态方式加载视图的情况下在 UIViewController 之间切换的正确方法是什么
我正在尝试在不使用导航控制器、选项卡栏控制器等的情况下完成切换视图。我目前正在使用 Cocos2d 控制器类 ReplaceScene 方法来完成此任务。我的应用程序需要大约 40 个视图控制器,每个视图控制器都有一些 UIButton,可以将它们带到任何其他视图控制器。
例如,视图控制器 1 可能具有带您查看控制器 2 的按钮 视图控制器 2 可能有链接到 3、4、5、12 的按钮 视图控制器 4 可能需要链接到视图控制器 17、5 和 3
我读过的每个教程和文档都只讨论使用导航控制器、选项卡栏或以模式方式推送视图。这些解决方案都不符合我的特定要求。
Cocos2d 有“replaceScene”方法,它完全可以满足我的需要,但是混合我需要的许多 UIKit 控件使得在 Cocos2d 中开发整个项目成为一场噩梦。
我正在寻找一些东西,我可以让用户点击一个按钮,将指定的视图控制器/视图转换加载到该视图,并从内存中卸载以前的视图控制器。有什么想法吗?
I'm trying to accomplish switching views without using a navigation controller, tab bar controller etc. I am currently accomplishing this using Cocos2d director class replaceScene method. My application will need to have around 40 view controllers, each with a few UIButtons that could take them to any other view controller.
For instance View controller 1 may have buttons that take you to view controller 2
View Controller 2 may have buttons that link to 3,4,5,12
view controller 4 may need to link to view controller 17, 5 and 3
Every tutorial and bit of documentation I've read only discusses using Navigation Controllers, Tab bars or pushing views modally. None of these solutions fits my particular requirements.
Cocos2d has the "replaceScene" method which does exactly what I need, but mixing the many UIKit controls that I need makes developing this entire project in Cocos2d a nightmare.
I'm looking for something where I can have the user tap a button which will load a specified view controller/view transition to that view, and unload the previous view controller from memory. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有一个根视图控制器,其中包含视图控制器的引用。还要对每个视图控制器中的根视图控制器进行弱引用,就像在委托模式中一样。如果其中一个视图控制器想要进行视图转换,请向根视图控制器发送一条消息。让根视图控制器隐藏当前视图并取消隐藏下一个视图,如果需要,可以使用动画。
基本上,您正在实现一个比 UINavigationController 和 UITabBarController 简单得多的视图容器。您可能可以使用选项卡栏控制器实现相同的效果并隐藏选项卡栏视图,但我会实现一个自定义的。
Have a root view controller which has references of your view controllers. Also make a weak reference to the root view controller in each view controller, as in a delegate pattern. If one of the view controllers wants to make a view transition, send a message to the root view controller. Let the root view controller hide the current view and unhide the next view, using an animation if you want.
Basically you are implementing a view container much simpler than UINavigationController and UITabBarController. You could probably achieve the same thing using the tab bar controller and hide the tab bar view, but I would implement a custom one.