実行時に SKLabelNode のテキストを変更しようとしていますが、次のエラーでアプリがクラッシュします: CRASH: -[SKLabelNode label]: unrecognized selector sent to instance
selectNodeForTouch:(CGPoint)touchlocation
次のようにメソッドから呼び出しています。
if ([[node name]isEqualToString:@"e"]) {
// add current riddle to favourites and change the icon of the star
button *btn = (button *)[self nodeAtPoint:touchLocation];
btn.label.text = @"d";
[(GameViewController *)self.view.window.rootViewController addToFavourites:_currentTomhais];
NSLog(@"Favourited");
}
ボタン オブジェクトには、次のインターフェイスがあります。
@interface button : SKSpriteNode
@property (nonatomic, retain) SKLabelNode *label;
そして、button.m ファイルで次のように初期化されます
@implementation button
-(instancetype) initWithString:(NSString *)character fontNamed:(NSString *)font size:(float)size{
self = [super init];
if (self) {
[self setSize:CGSizeMake(size, size)];
//icon Text
_label = [[SKLabelNode alloc] initWithFontNamed:font];
_label.name = character;
_label.fontSize = size;
_label.fontColor = [UIColor colorWithRed:150.0f/255.0f
green:166.0f/255.0f
blue:173.0f/255.0f
alpha:1];
[_label setText:character];
_label.position = CGPointMake(0, 0);
[self addChild:_label];
}
return self;
}
アプリをクラッシュさせることなく、実行時にこのアイテムのテキストを変更する方法はありますか?