gpt4 book ai didi

cocoa-touch - 我们什么时候应该使用 pushScene 和 replaceScene?

转载 作者:行者123 更新时间:2023-12-02 00:40:07 25 4
gpt4 key购买 nike

我是 cocos2d,我正在使用 pushScene 和 replaceScene 移动到下一个场景。但是,我很困惑我们应该使用哪个?

当我在某些地方使用 replaceScene 时,应用程序崩溃并出现类似

的错误
-[UITextView length]: unrecognized selector sent to instance 0x842a750  
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UITextView length]: unrecognized selector sent to instance 0x842a750'

但是,在我的程序中,我没有将长度传递给 UITextView。我的程序是这样的
在 scene1 中,我有 UITextView,我正在用 scene2 替换这个场景。然后

-(id)buttonPressed:(id)sender
{
[description removeFromSuperview]; // It is the textView(description)
CCScene *Scene = [CCScene node];
CCLayer *Layer = [scene2 node];

[Scene addChild:Layer];

[[CCDirector sharedDirector] setAnimationInterval:1.0/60];
[[CCDirector sharedDirector] replaceScene: Scene];
}

但是,当我在存在 replaceScene 的情况下使用 pushScene 时,它​​运行良好。请澄清我应该在哪些情况下使用哪个?

谢谢

最佳答案

几乎在所有情况下您都希望使用 replaceScene。 pushScene 方法将之前的场景保存在内存中,这很可能是它没有崩溃的原因。那个场景有些地方不太对劲,当它在 replaceScene 之后解除分配时,就会发生崩溃。与cocos2d的替换场景系统无关。

您在场景 1 中的 UITextView 可能发布得太频繁了。如果它被创建为自动释放对象,请不要向它发送释放消息。

关于cocoa-touch - 我们什么时候应该使用 pushScene 和 replaceScene?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2881805/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com