gpt4 book ai didi

iphone - NSMutableArray addObject 错误

转载 作者:行者123 更新时间:2023-12-03 20:19:44 25 4
gpt4 key购买 nike

我无法将对象添加到“easyQArray”(NSMutableArray)中。当我在本地定义数组时它确实有效,但是当我将声明移动到 .h 文件中时它不再起作用。

当我尝试访问数组中不存在的索引时,应用程序崩溃:

// Create question arrays
if (easyPlayers > 0) {
for (int XX = 0; XX < easyQuestions; XX++) {
[easyQArray addObject: [myArray objectAtIndex: easyQStartPos]];
NSLog(@"myArray: %@", [myArray objectAtIndex: easyQStartPos]);
NSLog(@"easyQArray: %@", easyQArray);
easyQStartPos = easyQStartPos + 1;
}
}

输出:

2010-12-28 15:52:57.636 XX_v2[11582:207] myArray: 205
2010-12-28 15:52:57.636 XX_v2[11582:207] easyQArray: (null)
2010-12-28 15:52:57.636 XX_v2[11582:207] myArray: 71
2010-12-28 15:52:57.637 XX_v2[11582:207] easyQArray: (null)
2010-12-28 15:52:57.637 XX_v2[11582:207] myArray: 94
2010-12-28 15:52:57.638 XX_v2[11582:207] easyQArray: (null)
2010-12-28 15:52:57.638 XX_v2[11582:207] myArray: 133
2010-12-28 15:52:57.638 XX_v2[11582:207] easyQArray: (null)
2010-12-28 15:52:57.639 XX_v2[11582:207] myArray: 142
2010-12-28 15:52:57.640 XX_v2[11582:207] easyQArray: (null)

最佳答案

看来你甚至没有初始化你的数组。从您的描述来看,您似乎将其声明为属性,因此在类 init 方法中调用 alloc/init 应该可以解决您的问题。

easyQArray = [[NSMutableArray alloc] init];  

关于iphone - NSMutableArray addObject 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4546951/

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