【发布时间】:2011-10-09 17:19:39
【问题描述】:
我得到了下一个代码,非常简单:
//SecondViewController.m
if(contentRvController==nil){
contentRvController = [[ContentView alloc]
initWithNibName:@"ContentView" bundle:nil]; //ContentView is a custom UIViewController
....
[self.view addSubview:contentRvController.view];
}
else{
contentRvController.view.hide = YES;
[contentRvController release];
contentRvController = nil;
}
基本上,当从一个按钮启动代码时,如果 UIViewController 不存在,则创建一个并显示它(它旨在显示在更大的主桌面视图上,这是 SecondViewController 视图)。如果已打开,请将其关闭并删除以释放资源。
现在,contentRvController 是 ContentView 的一个实例,一个自定义 UIViewController。它有自己的关闭 UIButton,其中 IBAction 是这样的:
//ContentView.m
- (IBAction) closeView {
self.view.hidden = YES;
[self release];
self = nil;
}
现在,当从 SecondViewController 触发时,释放 contentRvController 工作正常(或者在我看来是这样),视图出现并消失。但是当点击 ContentView 关闭按钮时,它也会关闭视图,但是当尝试再次打开它时,if(contentRvController==nil) 返回FALSE,所以我必须点击两次按钮才能再次显示 ContentView。
在我看来,self = nil; 与 contentRvController = nil; 的工作方式不同,尽管它应该都指向同一个地方,我迷失了这个。
¿有什么想法吗?来自墨西哥的欢呼
【问题讨论】:
标签: objective-c ios cocoa-touch self