0
我在我的应用程序中使用ARC。 现在我面临一个真正的问题。我需要从左向右动画两个视图控制器。所以,我只是在动画按钮操作的两种观点一样,iPhone对象不会死亡
// thanks to stackoverflow for this code
test *control = [[test alloc] initWithNibName: @"test" bundle: nil];
control.view.frame = self.view.frame;
control.view.center = CGPointMake(self.view.center.x + CGRectGetWidth(self.view.frame), self.view.center.y);
[self.view.superview addSubview: control.view];
// Animate the push
[UIView beginAnimations: nil context: NULL];
[UIView setAnimationDelegate: self];
[UIView setAnimationDidStopSelector: @selector(pushAnimationDidStop:finished:context:)];
control.view.center = self.view.center;
self.view.center = CGPointMake(self.view.center.x - CGRectGetWidth(self.view.frame), self.view.center.y);
[UIView commitAnimations];
- (void) pushAnimationDidStop: (NSString *) animationID finished: (NSNumber *) finished context: (void *) context
{
[self.view removeFromSuperview];
}
,并在第二视图控制器我也一样,但改变动画方向。
我真正的问题是当我运行这段代码时,每次创建另一个类的对象时它都不会释放。通过分析这些代码,发现每次对象处于活动状态时它都不会死亡,并且内存分配也会增加。
你在哪里分配你的*控制?它在你的按钮动作?如果是这样,那么,你的问题就在那里,因为你每次按动按钮时你的代码都会分配一个新的控制器。如果你仍然想要在按钮中分配视图,无论出于何种原因,可以使用if(!yourViewController){分配你的控制器},以便应用程序只分配一个新的控制器,如果旧的控制器已经自动释放弧(弧自动dealloc对象的保持无效/或没有它的意见加载)* CMIIW – 2012-04-23 09:15:04