#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;
This is the declaration of my UCRootViewController which should manage these sub-viewControllers. He will later also become their delegate to handle when one controller should be shown or not.
The rootViewController is held strong in the UIAppDelegate and will remain active all the time.
So is it correct to make those sub-viewControllers weak? I'm not 100% sure, but as far as I understand weak pointers get deallocated when there is no strong pointer pointing to them. So as the root is strong, it's correct to make them weak, right?
#import <UIKit/UIKit.h>
@class UCRootViewController;
@interface UCOverviewController : UIViewController
@property (weak, nonatomic) UCRootViewController *rootviewController;
This is the header of one of my sub-viewControllers. They have a weak pointer to the (later) delegate rootviewController. Is it enough to declare @class UCRootviewController
to make them call the delegate methods? Do I even need this?
thanks
EDIT: I just read a nice article about ViewControllers and the passage:
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.
It says use a weak reference, what's your opinions on this?