了解UIViewController层次结构 [英] Understanding UIViewController hierarchy

查看:87
本文介绍了了解UIViewController层次结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好-此刻我的大脑正在被炸,所以任何帮助都将不胜感激.

Ok - my brain is being fried at the moment so any help would be appreciated.

我的应用程序中有多个UIViewController的子类.让我们称它们为VC_A, VC_B, VC_C, VC_D.

I have multiple subclasses of UIViewController in my app. lets call them VC_A, VC_B, VC_C, VC_D.

用户通过触摸每个视图上的按钮进行交互.

The users interacts by touching buttons on each of the views.

因此,我的AppDelegate添加了VC_A:

So my AppDelegate adds in VC_A:

//Add the view controller's view to the window and display.  
[self.window addSubview:viewController.view];  
[self.window makeKeyAndVisible];  

VC_A然后使用presentModalViewController加载VC_B:

VC_A then loads VC_B by using presentModalViewController:

    VC_B *tempView = [[VC_B alloc] initWithNibName:@"temploadingscreen" bundle:nil];
    [self presentModalViewController:tempView animated:NO];
    [tempView release];  

,直到获得

VC_A 
- VC_B  
    - VC_C  
       - VC_D  

,但是当我在VC_D上调用presentModalViewController将我带到VC_C时,我希望它是VC_C的新实例,而不是原始实例.

but then when I call presentModalViewController on VC_D to take me to VC_C I want it to be a new instance of VC_C and not the original instance.

所以我的问题是如何执行此操作-我是否需要使用[self dismissModalViewControllerAnimated:NO];删除视图的旧实例.

So my question is how to you go about doing this - do I need to use [self dismissModalViewControllerAnimated:NO]; to remove the old instances of the views.

任何帮助都将不胜感激,因为我已经为此进行了搜索,但是所有教程和内容都使用导航栏来控制导航-由于应用程序的类型,我无法使用其中的一个.在UIViewController的新实例之间正确移动的任何有效代码示例都很好.

Any help would be gratefully appreciated as I have done searches for this but all the tutorials and stuff use a navbar to control the navigation - and i cant use one because of the type of app. Any working code examples of properly moving between new instances of UIViewControllers would be great.

推荐答案

我决定以一种不同的方式进行此操作,从而完全满足我的需求.

I decided to do this a different way which works perfectly for what I need.

我要做的是在基本框中创建了基本的ViewController,在viewDidAppear方法中没有任何设置,我基于全局NSNumber的值调用了其他viewController(使用presentModalViewController).

What I did was I created the base ViewController with nothing in the xib and in the viewDidAppear method I called the other viewControllers (using presentModalViewController) based on the value of a global NSNumber.

因此,当我转到其他任何一个视图控制器而不是它们调用另一个viewController时,他们只需设置全局变量即可指示要加载的视图,然后关闭当前视图(使用dismissModalViewController).

Thus when I go to any of the other viewcontrollers rather than them call another viewController they simply set the global variable indicating which view to load and then close the current view (using dismissModalViewController).

这样,每个viewControllers实例都将关闭,并释放内存.

This way each instance of the viewControllers are closed and the memory released.

我创建了一个示例项目,并将其放在github https://github.com/sregorcinimod/Open

I have created an example project and placed it on github https://github.com/sregorcinimod/Open

只需在下载中查看,即可在其中看到

Just look in the Downloads you'll see it there

这篇关于了解UIViewController层次结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆