已编辑
这是我在编码过程中遇到的一个非常常见的问题,请看一下。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
// Adding Landing screen landscape on mainwindow
self.landingViewController = [[LandingViewController alloc] initWithNibName:@"LandingViewController" bundle:nil];
[self.window addSubview:self.landingViewController.view];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
#import <UIKit/UIKit.h>
@class RecentPlanViewController;
@class ChevronViewController;
@interface LandingViewController : UIViewController
{
UINavigationController *navigationController;
// custom view controllers
RecentPlanViewController *recentPlanViewController;
ChevronViewController *chevronViewController;
}
- (void)popView:(NSNotification *)notification;
@property (nonatomic,retain) UINavigationController *navigationController;
@property (nonatomic,retain) RecentPlanViewController *recentPlanViewController;
@property (nonatomic,retain) ChevronViewController *chevronViewController;
@end
self.recentPlanViewController = [[RecentPlanViewController alloc] initWithNibName:@"RecentPlanViewController" bundle:nil];
[self.recentPlanViewController loadView]; // if I skip this : Memory to recentPlanViewController's IVs not allocated.
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.recentPlanViewController ];
#import <UIKit/UIKit.h>
@class RecentPlanCell;
@interface RecentPlanViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
IBOutlet UITableView *recentPlanTableView; // Main recent TableView
RecentPlanCell *recentPlanCell;
IBOutlet UIButton *createPlanButton;
IBOutlet UIButton *viewAllPlanButton;
BOOL isViewingAllPlans; // Yes if view all plan pressed
}
@property (nonatomic,retain) RecentPlanCell *recentPlanCell;
@property (nonatomic,retain) IBOutlet UIButton *createPlanButton;
@property (nonatomic,retain) IBOutlet UIButton *viewAllPlanButton;
@end
以上编写的代码有两个结论。
1.如果我使用 loadView 方法。它调用视图控制器的视图并将内存分配给 IBOutlets,而不用于其他self.recentPlanViewController
实例变量。
2.如果我跳过第二行代码,即使将其用作rootVC,它也不会为任何IVR分配内存。
请指导我,我违反的内存管理概念是什么!
谢谢