UIViewController push&流行的

时间:2012-06-29 06:01:31

标签: iphone ios release dealloc pushviewcontroller

我面临着推送和推出的问题。弹出我的UIViewController。我有两个UIViewControllers说A& B

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

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];

我还从[super dealloc]

致电B
-(void) dealloc
{
   [super dealloc];
}

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

这个问题是因为我申请了动画吗?

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

任何帮助,建议!

1 个答案:

答案 0 :(得分:1)

尝试在动画完成块中释放bView

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