为什么我无法释放添加到窗口的视图的导航控制器
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self setWindow:[[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]];
// Override point for customization after application launch.
//self.window.backgroundColor = [UIColor whiteColor];
// Create First view
FirstViewController *firstViewCTL = [[FirstViewController alloc] init];
// Create UINavigationController
UINavigationController *navCTL = [[UINavigationController alloc] init];
[[navCTL navigationBar] setBarStyle:UIBarStyleBlack];
[navCTL pushViewController:firstViewCTL animated:NO];
[firstViewCTL release];
[[self window] addSubview:navCTL.view];
[navCTL release];
[[self window] makeKeyAndVisible];
return YES;
}
我知道添加子视图(addSubview:)将保留要添加的视图。但为什么我现在无法释放拥有已保留视图的导航控制器(navCTL)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self setWindow:[[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]];
// Override point for customization after application launch.
//self.window.backgroundColor = [UIColor whiteColor];
// Create First view
FirstViewController *firstViewCTL = [[FirstViewController alloc] init];
// Create UINavigationController
UINavigationController *navCTL = [[UINavigationController alloc] init];
[[navCTL navigationBar] setBarStyle:UIBarStyleBlack];
[navCTL pushViewController:firstViewCTL animated:NO];
[firstViewCTL release];
[[self window] addSubview:navCTL.view];
[navCTL release];
[[self window] makeKeyAndVisible];
return YES;
}
I understand that adding subview (addSubview:) will retain the view to be aded. But why I can't now release my navigation controller (navCTL) that own the views that has already been retained
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
-addSubview:
保留视图,而不是视图控制器。您可以使用
UIWindow
的rootViewController
属性(iOS 4 及更高版本)来保留视图控制器,它还可以节省您自己将视图添加为子视图的麻烦。-addSubview:
retains the view, not the view controller.You can use
UIWindow
'srootViewController
property (iOS 4 and higher) to retain the view controller, it also saves you adding the view as a subview yourself.