【问题标题】:Issue in UIViewController push & popUIViewController 推送和弹出中的问题
【发布时间】:2012-06-29 06:01:31
【问题描述】:

我遇到了推送和弹出 UIViewController 的问题。我有两个 UIViewController 说 A 和 B。

我写了一个IBAction,其中我从A 推送到B 喜欢,

B *bView=[[B alloc] initWithNibName:@"B" bundle:nil];
[UIView beginAnimations:@"animation" context:nil];
[UIView setAnimationDuration:0.7];
[self.navigationController pushViewController:bView animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations];

[bView release]; //Problem is here, If I comment this line, it works fine! else it crashes after my some transitions from A [push] B, B [pop] A.

现在在B 我已经写了一个IBAction 来弹出到A,如下所示

[UIView beginAnimations:@"animation" context:nil];
[UIView setAnimationDuration:0.7];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[self.navigationController popViewControllerAnimated:NO];
[UIView commitAnimations];

我也从B 打电话给[super dealloc]

-(void) dealloc
{
   [super dealloc];
}

如果我不释放bView,它将不会调用dealloc,并且可能会产生内存问题。

这是因为我应用了动画造成的吗?

我尝试了所有其他方式,例如autorelease、设置bView=nil; 等,但这些对我不起作用!

任何帮助,建议!

【问题讨论】:

  • 【bView release】没有问题;您的 B 类代码中还有其他问题,您可以使用 NSZombie 来跟踪问题的确切位置。或者您可以粘贴 B 类的代码。
  • NSZombie 已启用,它显示消息message sent to deallocated reference
  • 它会显示一些内存地址,在控制台上你可以使用“po memory-address”查看是哪个实例导致了这个问题。

标签: iphone ios release dealloc pushviewcontroller


【解决方案1】:

尝试在动画完成块内释放bView。

您可以使用旧样式+ setAnimationDidStopSelector: 或者如果不需要支持iOS4之前的设备,可以使用动画块animateWithDuration:delay:options:animations:completion:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-07
    • 2011-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-13
    • 2012-09-18
    • 1970-01-01
    相关资源
    最近更新 更多