我有以下委托文件。我在MainWindow.xib中的AboutViewController加载了AboutViewController.xib,并且aboutViewController出口连接到它。此外,navController从另一个ViewController.xib加载。 AboutViewController的视图在启动时显示,并在一秒钟后删除,因此我通过将ivar设置为nil来释放其视图控制器。
由于关于视图控制器是由XCode自动加载的,我自己做错了什么(泄漏内存等),我自己手动设置为零?为什么或为什么不呢?
由于
- MyProjAppDelegate.h
#import <UIKit/UIKit.h>
@interface MyProjAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UIViewController *aboutViewController;
UINavigationController *navController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UIViewController *aboutViewController;
@property (nonatomic, retain) IBOutlet UINavigationController *navController;
@end
- MyProjAppDelegate.m
#import "MyProjAppDelegate.h"
#import "AboutViewController.h"
@implementation MyProjAppDelegate
@synthesize window;
@synthesize aboutViewController;
@synthesize navController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window addSubview:aboutViewController.view];
[window makeKeyAndVisible];
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(showMainView) userInfo:nil repeats:NO];
}
-(void)showMainView {
[aboutViewController.view removeFromSuperview];
self.aboutViewController = nil;
[window addSubview:navController.view];
}
- (void)dealloc {
[navController release];
[aboutViewController release];
[window release];
[super dealloc];
}
@end
答案 0 :(得分:2)
由于关于视图控制器是由XCode自动加载的,我自己做错了什么(泄漏内存等),我自己手动设置为nil?
不,你没有做错任何事,因为你正在使用属性访问器方法(self.aboutViewController
)将其设置为nil
;访问者将负责release
。 (并且,在发布它之前,你正在将它从superview 中删除: - )