#import <UIKit/UIKit.h> #import "UCMapviewController.h" #import "UCMenuviewController.h" #import "UCOverviewController.h" @interface UCRootViewController : UIViewController @property (weak,nonatomic) UCMapviewController *mapviewController; @property (weak,nonatomic) UCMenuviewController *menuviewController; @property (weak,nonatomic) UCOverviewController *overviewController;
这是我的UCRootViewController的声明,它应该管理这些子viewControllers.他后来也将成为他们的代表,以便在何时应该显示一个控制器时进行处理.
rootViewController在UIAppDelegate中保持强大,并将一直保持活动状态.
那么使这些子视图控制器变弱是否正确?我不是100%肯定,但据我所知,当没有强指针指向它们时,弱指针会被释放.因为根很强大,让它们变弱是正确的,对吗?
#import <UIKit/UIKit.h> @class UCRootViewController; @interface UCOverviewController : UIViewController @property (weak,nonatomic) UCRootViewController *rootviewController;
这是我的一个子viewControllers的标题.它们有一个指向(稍后)委托rootviewController的弱指针.是否足以声明@class UCRootviewController使它们调用委托方法?我甚至需要这个吗?
谢谢
编辑:我刚读了a nice article about ViewControllers和段落:
Always use high-quality view controller containers or
+[UIViewController presentModalViewController:animated:] to display view controllers in your application. If you need to keep a reference
to a view controller somewhere,use a weak reference,except if you
really want it to stay alive longer for caching purposes. In such
cases,be sure to correctly respond to low-memory conditions.
它说使用弱参考,你对此有何看法?