IOS:presentmodalviewcontroller 版本
我使用此代码打开视图控制器
self.secondViewController = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
[self presentModalViewController:self.secondViewController animated:YES];
[self.secondViewController release];
,但如果我使用 [self.secondViewController release];
当我第二次调用此代码时它会崩溃,因为
[FirstViewController performSelector:withObject:withObject:]: message sent to deallocated instance 0x18a890
如果我不使用它,一切都可以,但是在这种情况下,我什么时候可以释放我的第二个视图控制器? 你能帮助我吗?
I use this code ti open a viewcontroller
self.secondViewController = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
[self presentModalViewController:self.secondViewController animated:YES];
[self.secondViewController release];
but if i use [self.secondViewController release];
when I call this code second time it crash because
[FirstViewController performSelector:withObject:withObject:]: message sent to deallocated instance 0x18a890
if I don't use it, it it's all ok, but in this situation when can I dealloc my secondviewcontroller?
can you help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从您的代码(
self.secondViewController
)来看,我的理解是您已将secondViewController
声明为 .h 文件中的变量,并且@synthesize
将其添加到您的 .m 文件中。如果是这样的话,我宁愿做以下事情
在您的
- (void)dealloc
方法中,我将添加[self.secondViewController release];
并在- (void)viewDidUnload
中添加添加[self setSecondViewController:nil];
。上面的代码假设您不使用 ARC。
如果您使用 ARC,我将修改我的代码如下:
From your code (
self.secondViewController
), my understanding is that you have declaredsecondViewController
as a variable in your .h file, and@synthesize
'd it in your .m file.If that's right, I would rather do the followings
and in your
- (void)dealloc
method, I would add[self.secondViewController release];
and in- (void)viewDidUnload
I would add[self setSecondViewController:nil];
.The above code is with the assumption that you are not using ARC.
If you are using ARC, I would revise my code as follows: