0
我想重新加載當前的場景,然後init
發生然後dealloc
。返回NULL?
我想在dealloc上有條件返回,如果它從當前場景調用。
我試圖這樣的:
if ([[[CCDirector sharedDirector] runningScene] getChildByTag:16])
return;
和
[[[CCDirector sharedDirector] runningScene] isKindOfClass:[HelloWorldLayer class]]
兩個給我NULL,而條件是不正確的。
爲什麼?
我的場景是這樣的:
+(CCScene *) scene
{
// 'scene' is an autorelease object.
CCScene *gameScene = [CCScene node];
// 'layer' is an autorelease object.
HelloWorldLayer *layer = [HelloWorldLayer node];
layer.tag=16;
// add layer as a child to scene
[gameScene addChild: layer];
// return the scene
return gameScene;
}
我怎樣才能消除的dealloc時,我只刷新現場?
不知道我完全理解你的問題,但:有沒有辦法中止的dealloc - 這是一個單程,恰巧你的對象已被釋放之後。您需要首先防止您的對象被釋放。 – nielsbot 2012-02-23 22:09:33
我不認爲這是真的。 return dealloc將退出該函數。 – Curnelious 2012-02-23 22:16:53
不,對象將被釋放。實際上,當調用dealloc時,運行時只是讓你有機會釋放你保留的對象,但是當dealloc結束時它會釋放你的對象。所以當你打電話回來的時候,你基本上告訴他:好的,你現在可以釋放這個對象。 – sch 2012-02-23 22:34:40