简体   繁体   English

MMDrawerController:将相同的实例leftViewController用于两个单独的中心View Controller

[英]MMDrawerController: Using the same instance leftViewController for two separate center View Controllers

As stated in the title, I'm using MMDrawerController. 如标题中所述,我正在使用MMDrawerController。 To keep things simple, I have 3 ViewControllers, A, B, and C. 为简单起见,我有3个ViewController,A,B和C。

A is the initial ViewController, and it contains a side ViewController, which is C. A是初始ViewController,它包含一个侧面ViewController,即C。

From A, I can segue to B. B also contains a side ViewController, which is C. 从A,我可以选择B。B还包含一个侧面ViewController,即C。

I decided it isn't worth the hassle for both A and B to have separate instances of C as their individual side ViewControllers, so I decided to use the same instance of C as both of their side ViewControllers. 我认为A和B将C的单独实例作为它们各自的侧面ViewController并不麻烦,所以我决定使用C的实例作为它们的两个侧面ViewController。

When I start up the app, everything is great. 当我启动应用程序时,一切都很好。 I segue to B, and I see the same instance of C as the side ViewController. 我选择B,然后看到与侧面ViewController相同的C实例。 The problem is that when I dismiss B via self.dismissViewControllerAnimated(true, completion: nil) to get back to A, I no longer see C as the side ViewController. 问题是,当我通过self.dismissViewControllerAnimated(true, completion: nil)解散B以返回A时,我不再将C视为ViewController的一面。 The side ViewController is completely black. 侧面的ViewController是完全黑色的。

Even though I dismissed B, I know I didn't release C from memory. 即使我解雇了B,我也知道我没有从内存中释放C。 I still have an instance to it, I can still call stuff in it, and the MMDrawerController that encapsulates A still thinks that C is its side ViewController. 我仍然有一个实例,我仍然可以在其中调用东西,并且封装A的MMDrawerController仍然认为C是其侧面ViewController。

Why is this happening? 为什么会这样呢? How can I handle this? 我该如何处理?

Do I need State Restoration for this? 为此,我需要状态恢复吗?

I did It several times but in another way... I use C as menu and 'D' as a UINavigatorController with A as rootviewController for the center screen. 我做了几次,但是用另一种方式...我使用C作为菜单,使用'D'作为UINavigatorController使用A作为中心屏幕的rootviewController So You can push/pop from A to B without change C. 因此,您可以在不更改C的情况下从A推入/弹出B

Hope It helps 希望能帮助到你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM