UIViewController 的 dealloc 中的 [super dealloc] 在 iPad 中出现问题
我正在开发一个应用程序,我将一个视图控制器推送到 UINavigationController 上,并在导航控制器保留它时立即释放它。当我弹出视图控制器时,将按预期调用 dealloc
方法但问题是应用程序崩溃了。如果我通过启用 NSZombie 在 GDB 中观察到它说 -[MyViewController isKindOfClass:]: 消息发送到已释放的实例0x6847a00
。如果我从视图控制器的dealloc
方法中删除[super dealloc]
,它的工作就很好。我没有其他东西dealloc 方法除了 [super dealloc] 之外。这里可能有什么问题,任何人都可以帮忙。代码片段如下:
MyViewController *myViewController = [[MyViewController alloc] initWithNibName:nil bundle:nil];
myViewController.path = selectedPath; //very important to set path here
myViewController.parentViewController = self;
[self cleanBookshelf];
[self.navigationController pushViewController:myViewController animated:NO];
[myViewController release];
[indicatorView removeFromSuperview];
[loadingindicator stopAnimating];
我正在 myViewController 的一个操作方法中弹出
-(IBAction)goBack:(UIButton*)sender{
[self.navigationController popViewControllerAnimated:YES];
}
I am working on an application where i am pushing one view controller on to a UINavigationController and releasing it immediately as the navigation controller retains it.When i am poping the view controller the dealloc
method is being called as expected but the problem is the app is getting crashed.If i observe in GDB by enabling NSZombie
its saying that -[MyViewController isKindOfClass:]: message sent to deallocated instance 0x6847a00
.If i remove [super dealloc]
from my view controller's dealloc
method its working just fine.I have nothing else in dealloc method except [super dealloc].What could be the problem here, can any one please help.The code snippet is below:
MyViewController *myViewController = [[MyViewController alloc] initWithNibName:nil bundle:nil];
myViewController.path = selectedPath; //very important to set path here
myViewController.parentViewController = self;
[self cleanBookshelf];
[self.navigationController pushViewController:myViewController animated:NO];
[myViewController release];
[indicatorView removeFromSuperview];
[loadingindicator stopAnimating];
and i am poping in one action method of myViewController as
-(IBAction)goBack:(UIButton*)sender{
[self.navigationController popViewControllerAnimated:YES];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只是猜测,但我怀疑问题出在这一行:
UIViewController 的
parentViewController
属性被标记为readonly
,我认为这是一个强烈的信息,您不应该这样做搞乱它。Just guessing, but I suspect that the problem is with this line:
UIViewController's
parentViewController
property is markedreadonly
, and I'd take that as a strong message that you shouldn't mess with it.