简体   繁体   English

在CATransition之后发布视图控制器:我这样做对吗?

[英]Releasing a view controller after a CATransition: Am I doing this right?

My application is loading a first view (used to login into a Web service). 我的应用程序正在加载第一个视图(用于登录Web服务)。 When the login is successful, it performs a CATransition (basic kCATransitionFromRight) to show a second view and hides the first view. 登录成功后,它将执行CATransition(基本kCATransitionFromRight)以显示第二个视图并隐藏第一个视图。 I've set the delegate of the transition to self so I can use -(void)animationDidStop:(CATransition *)theAnimation finished:(BOOL)flag . 我已将过渡的委托设置为self,因此可以使用-(void)animationDidStop:(CATransition *)theAnimation finished:(BOOL)flag

When that method is called (right after the transition is over) I want to release the first view since I won't need it anymore. 调用该方法时(过渡结束后),我想释放第一个视图,因为我不再需要它了。 However, when I call [firstView release] (in animationDidStop: ) the retain count doesn't seem to change. 但是,当我调用[firstView release] (位于animationDidStop: )时,保留计数似乎没有变化。 I used [loginView retainCount] to check this and since I know it's not always reliable I was wondering: am I doing this right? 我使用[loginView retainCount]进行了检查,由于我知道它并不总是可靠的,所以我想知道:我这样做对吗?

Thank you. 谢谢。

taken from the book "Cocoa Touch for iPhone OS 3" is a similar approach. 摘自《 iPhone OS 3的Cocoa Touch》一书是类似的方法。
They set up an animation remove the old subview, add the new one and then commit the animation. 他们设置了动画,删除了旧的子视图,添加了新的子视图,然后提交了动画。

Jilouc in his comment is right, forget to check "retaincount"... Jilouc在他的评论中是正确的,忘记检查“ retaincount” ...

if you want to be sure that your object view firstView just add a 如果您想确保您的对象视图firstView只需添加一个

NSLog(@"i'm removing myFirstView"); 

in its 在其

-(void)dealloc{
}

method... 方法...

if you get that NSLog in debugger console window then be sure you had it removed/released in the right way... 如果您在调试器控制台窗口中看到该NSLog,请确保以正确的方式删除/发布了它。

btw... the right way could be something like this: 顺便说一句...正确的方法可能是这样的:

in animationDidStop: 在animationDidStop中:

if (firstView!=nil){
    [firstView.view removeFromSuperview];
    [firstView release];
    firstView=nil;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM