我遇到了推送和弹出 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
、set bView=nil;
等,但这些对我不起作用!
任何帮助,建议!
最佳答案
尝试在动画完成 block 内释放bView
。
您可以使用旧样式+ setAnimationDidStopSelector:
或者如果您不需要支持iOS4之前的设备,您可以使用动画 block animateWithDuration:delay:options:animations:completion:
关于iphone - UIViewController 推送和弹出问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11256796/