gpt4 book ai didi

ios - 将对象添加到 NSMutableArray 将不起作用

转载 作者:行者123 更新时间:2023-11-28 19:57:48 25 4
gpt4 key购买 nike

我正在尝试使用临时数组 (tempArray) 制作一个包含 3 个对象的数组 (shopImages3)。包含所有开头字符串的大数组是 shopImages。

此时大数组包含6个字符串。这意味着它在

中出现了 2 次

"if((i == 2) || (i == 5) || (i == 8) || (i == 11) || (i == 14) || (i == 18))"

声明。这很好用。但是 NSLogs 显示数组为空。

如何正确填充数组?

2014-08-28 14:01:52.575 Jump Game[3622:60b] this is temp array (null)
2014-08-28 14:01:52.575 Jump Game[3622:60b] this is shopimages array (null)
2014-08-28 14:01:52.576 Jump Game[3622:60b] this is temp array (null)
2014-08-28 14:01:52.576 Jump Game[3622:60b] this is shopimages array (null)

代码从这里开始

@interface ShopCollectionViewController ()
{
NSArray *shopImages;

NSMutableArray *shopImages3;
NSMutableArray *tempArray;
}

........

for ( int i = 0; i < [shopImages count]; i++)
{

[tempArray addObject: shopImages[i]];

if((i == 2) || (i == 5) || (i == 8) || (i == 11) || (i == 14) || (i == 18))
{
NSLog(@"this is temp array %@", tempArray);
[shopImages3 addObject:tempArray];
NSLog(@"this is shopimages array %@", shopImages3);
[tempArray removeAllObjects];
}
}

最佳答案

看起来你没有初始化数组。在您的 init 中,您需要

tempArray = [NSMutableArray new];

关于ios - 将对象添加到 NSMutableArray 将不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25548373/

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