在我尝试将 [sender duration] 传递给 int dur 之前,一切正常。它适用于 TAG,但不适用于我自己的 var。我已经尝试过 INT 和 NSinteger 的 durationSpell。我想要做的是:我有 10 个不同的按钮来触发 spawnShoot,它们都有不同的持续时间。我想从单击的按钮中获取持续时间。
@interface ClassUI : NSObject {
CCMenuItemImage *button;
CCSprite *shot;
int durationSpell;
}
-----------------
ClassUI *spellshealP1 = [[ClassUI alloc]init];
spellshealP1.button = [CCMenuItemImage itemFromNormalImage:@"smallHeal.png" selectedImage:@"healempty.png" target:self selector:@selector(spawnShoot:)];
spellshealP1.button.tag = 101;
spellshealP1.durationSpell = 10;
CCMenu *player1menu = [CCMenu menuWithItems:spellshealP1.button, spellbighealP1.button, spellcureP1.button, spellfocusP1.button, spellpoisonP1.button, spellbfBallP1.button, spellsfBallP1.button, nil];
player1menu.position = ccp(MoveMenuInXP1, (768/2) - (numberOfButtons*buttonSize/2) + buttonSize/2);
[self addChild:player1menu];
-----------------
-(IBAction)spawnShoot:(id)sender{
int tag = [sender tag];
int dur = [sender durationSpell];
}