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

发布于 2024-10-22 17:59:51 字数 432 浏览 3 评论 0原文

我的应用程序正在加载第一个视图(用于登录 Web 服务)。当登录成功时,它会执行 CATransition(基本 kCATransitionFromRight)以显示第二个视图并隐藏第一个视图。我已将转换的委托设置为 self,以便可以使用 -(void)animationDidStop:(CATransition *)theAnimation finish:(BOOL)flag

当调用该方法时(在转换结束后),我想释放第一个视图,因为我不再需要它了。但是,当我调用 [firstView release] (在 animationDidStop: 中)时,保留计数似乎没有改变。我使用 [loginView keepCount] 来检查这一点,因为我知道它并不总是可靠,所以我想知道:我这样做对吗?

谢谢。

My application is loading a first view (used to login into a Web service). When the login is successful, it performs a CATransition (basic kCATransitionFromRight) to show a second view and hides the first view. I've set the delegate of the transition to self so I can use -(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. I used [loginView retainCount] to check this and since I know it's not always reliable I was wondering: am I doing this right?

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

再浓的妆也掩不了殇 2024-10-29 17:59:51

摘自《Cocoa Touch for iPhone OS 3》一书是类似的方法。
他们设置了一个动画,删除旧的子视图,添加新的子视图,然后提交动画。

taken from the book "Cocoa Touch for iPhone OS 3" is a similar approach.
They set up an animation remove the old subview, add the new one and then commit the animation.

小忆控 2024-10-29 17:59:51

Jilouc 在他的评论中是正确的,忘记检查“retaincount”...

如果你想确保你的对象视图firstView只需

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

在其

-(void)dealloc{
}

方法中添加一个...

如果你在调试器控制台窗口中得到 NSLog,那么请确保你以正确的方式删除/释放了它...

顺便说一句...正确的方法可能是这样的:

在animationDidStop中:

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

Jilouc in his comment is right, forget to check "retaincount"...

if you want to be sure that your object view firstView just add a

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...

btw... the right way could be something like this:

in animationDidStop:

if (firstView!=nil){
    [firstView.view removeFromSuperview];
    [firstView release];
    firstView=nil;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文