成员变量问题 [英] Member Variable Problems
问题描述
我在Spritebuilder中有一个按钮。特性如下:
文档根var: _playbutton
|选择器: play
目标: 文档根
Xcode中按钮的代码:
CCButton * _playButton;
- (void)play {
CCScene * scene = [CCBReader loadAsScene:@LevelSelect];
[[CCDirector sharedDirector] replaceScene:scene];
}
LevelSelect是Spritebuilder中的一个独立场景。
此代码工作,直到我有我的后退按钮,居住在场景LevelSelect的问题。要查看特性,请参阅我的使用Spritebuilder,崩溃按钮问题。
我的问题是,为什么这个代码会显示在我的调试控制台中?
CCBReader:找不到成员变量:_playbutton
但是,现在在LevelSelect中,Xcode找不到后退按钮。这是代码:
@implementation LevelSelect {
CCButton * _backbutton;
}
- (void)back {
CCScene * backScene = [CCBReader loadAsScene:@MainScene];
[[CCDirector sharedDirector] replaceScene:backScene];
}
正如你所看到的,你如何解决这个问题?
将变量放置为全局变量而不是成员变量的方式。 / p>
如果您希望将成员变量设为private,请将其放在 .m
文件中的以下位置:
@implementation YourClassName {
CCButton * _playButton;
}
I have a button in Spritebuilder. Characteristics are as follows:
Doc root var: _playbutton
| Selector: play
Target: | Document root
Code for the button in Xcode:
CCButton *_playButton;
- (void)play {
CCScene *scene = [CCBReader loadAsScene:@"LevelSelect"];
[[CCDirector sharedDirector] replaceScene:scene];
}
LevelSelect is a seperate scene in Spritebuilder.
This code worked until I had problems with my Back button, which inhabits scene LevelSelect. To see characteristics, see my "Using Spritebuilder, Crashing Buttons" question.
My question is, why does this code show up in my debugging console?
CCBReader: Couldn't find member variable: _playbutton
The answer works, kinda. But, now in LevelSelect, Xcode can't find the Back button. This is the code:
@implementation LevelSelect {
CCButton *_backbutton;
}
- (void)back {
CCScene *backScene = [CCBReader loadAsScene:@"MainScene"];
[[CCDirector sharedDirector] replaceScene:backScene];
}
As you can see I have incorporated the answer. How do you fix this?
The way you have placed the variable it is a global variable and not a member variable.
If you want the member variable to be private place it in the .m
file at the following position:
@implementation YourClassName {
CCButton *_playButton;
}
这篇关于成员变量问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!