gpt4 book ai didi

ios - 尝试使用点运算符显示来自另一个类的 AppDelegate 中的 NSMutable 数组对象的信息

转载 作者:行者123 更新时间:2023-11-29 11:00:39 25 4
gpt4 key购买 nike

我正在尝试找出如何访问和显示来自在我的 AppDelegate 中创建的 NSMutable 数组中的对象的信息。

来 self 的 AppDelegate.h

@property (readonly, retain) NSMutableArray *myRaces;
@end
AppDelegate * appDelegate;

来 self 的 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 中显示的值。

最佳答案

由于您将 orc 存储在数组中,因此您无法通过变量名访问它。您应该能够通过调用 objectAtIndex 来检索它,例如

appDelegate.theMass = ((TheRace*)[appDelegate.myRaces objectAtIndex:0]).massMod;

关于ios - 尝试使用点运算符显示来自另一个类的 AppDelegate 中的 NSMutable 数组对象的信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16031706/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com