When we should use pushScene and replaceScene?

大兔子大兔子 提交于 2019-12-12 16:26:15

问题


I cocos2d, I am using pushScene and replaceScene to move to next scene. But, I am confused which we should use?

When I am using replaceScene in some places app is crashing and giving errors like

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

But, in my program I am not passing length to UITextView. My program is in this way
In scene1 I have UITextView, and I am replacing this scene with scene2. Then

-(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];
}  

But, when I am using pushScene in presence of replaceScene it is working good. Please clarify me which one should use in which cases ?

Thank You


回答1:


You will want to use replaceScene in almost all cases. The pushScene method keeps the previous scene in memory, which is most likely why its not crashing. Something about that scene isn't quite right and when it deallocates after a replaceScene, the crash occurs. It has nothing to do with cocos2d's replace scene system.

Your UITextView in scene1 is probably released too often. If its created as an autorelease object, don't send it the release message.



来源:https://stackoverflow.com/questions/2881805/when-we-should-use-pushscene-and-replacescene

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!