我试图弄清楚如何访问和显示来自在我的 AppDelegate 中创建的 NSMutable 数组中的对象的信息。
从我的 AppDelegate.h
@property (readonly, retain) NSMutableArray *myRaces;
@end
AppDelegate * appDelegate;
从我的 AppDelegate.m
extern AppDelegate * appDelegate;
@synthesize myRaces;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
appDelegate = self;
TheRace * orc;
orc = [[TheRace alloc] init];
orc.raceTitle = @"Orc"; [orc modifyStatsFromRace:(NSString*)orc.raceTitle];
NSLog(@" test %d ", orc.massMod);
orc.raceData = @"Orcs are big burly stupid beasts";
myRaces = [[NSMutableArray alloc] init];
[myRaces addObject:orc];
}
我想从另一个类中调用 orc.massMod 的值,但无法弄清楚如何。我试过。
appDelegate.raceSelected = @"Orc";
NSLog(@"Orc");
appDelegate.theMass = appDelegate.myRaces.orc.massMod;
但是,“appDelegate.theMass = appDelegate.myRaces.orc.massMod;” 失败,错误提示...在对象类型“NSMutableArray *”上找不到属性“orc”
我如何称呼该信息?我想显示 massMod 的值,它在 appDelegate 内的 NSLog 中工作。“appDelegate.theMass”是在我的 UILabel 中显示的价值所在。