は、あなたがそれを得るためにKVCを使用することができるかもしれないん
//this works
if (maxunlocked > 1) {
filename = [NSString stringWithFormat:@"level%d.png", [[fliesArray objectAtIndex:2] intValue]];
filenameHi = [NSString stringWithFormat:@"level%dHi.png", [[fliesArray objectAtIndex:2] intValue]];
l2 = [SoundMenuItem itemFromNormalSpriteFrameName:filename selectedSpriteFrameName:filenameHi target:self selector:@selector(level:)];
}
// 。
float h1 = [object height];
float h2 = [[object valueForKey:@"height"] floatValue];
[EDIT]
私はあなたが言っているのか理解できませんでした。答えはいいえだ。変数名は動的に指定することはできません。あなたにできることはこれです:
// if `l2` is a member of self. (as in self.l2)
for (int i = 0; i<11; i++) {
if (maxunlocked > i) {
filename = [NSString stringWithFormat:@"level%d.png", [[fliesArray objectAtIndex:i] intValue]];
filenameHi = [NSString stringWithFormat:@"level%dHi.png", [[fliesArray objectAtIndex:i] intValue]];
//this is where I'm attempting to dynamically specify the SoundMenuItem instance name.
key = [NSString stringWithFormat:@"l%d", i];
tmp = [SoundMenuItem itemFromNormalSpriteFrameName:filename selectedSpriteFrameName:filenameHi target:self selector:@selector(level:)];
tmp.userData = (id)i;
[self setValue:tmp forKey:key];
}
}
[EDIT]
あなたはおそらく必要があり、再構造あなたの全体のクラス。
@interface myViewController: NSViewController {
UIButton *sound1;
UIButton *sound2;
SoundMenuItem *l1;
SoundMenuItem *l2;
}
@property (assign) IBOutlet UIButton *sound1; // connect up in IB
@property (assign) IBOutlet UIButton *sound2;
- (IBAction) clickSoundButton: (id)sender; // connect up to sound1 and sound2 in IB
- (SoundMenuItem) getSoundMenuItem: (int) i;
@end
@implementation myViewController
- (IBAction) clickSoundButton: (id)sender
{
if (sender == (id)sound1) l1 = [self getSoundMenuItem: 1];
if (sender == (id)sound2) l2 = [self getSoundMenuItem: 2];
}
- (SoundMenuItem) getSoundMenuItem: (int) i
{
if (maxunlocked <= i) return
NSString *filename = [NSString stringWithFormat:@"level%d.png", [[fliesArray objectAtIndex:i] intValue]];
NSString *filenameHi = [NSString stringWithFormat:@"level%dHi.png", [[fliesArray objectAtIndex:i] intValue]];
SoundMenuItem *sndMenuItem = [SoundMenuItem itemFromNormalSpriteFrameName:filename selectedSpriteFrameName:filenameHi target:self selector:@selector(level:)];
sndMenuItem.userData = (id)i;
return sndMenuItem; //(assuming it is auto-released)
}
@end
'l2'が作成された場所を表示すると助けになるかもしれません。 –