gpt4 book ai didi

iOS删除表单可变数组异常

转载 作者:行者123 更新时间:2023-11-28 18:03:32 26 4
gpt4 key购买 nike

我想从我的数组中删除一些东西但是我得到了异常

无法识别的选择器在删除

我的代码:

NSMutableArray* tempNewsArray = [[NSMutableArray alloc]init];
tempNewsArray = [[defaults objectForKey:@"NewsArray"]mutableCopy];
for(int i = 0;i< [tempNewsArray count]-1;i++)
{
if( (monthIntofNew - month <= 10 && monthIntofNew - month !=0) || ( monthIntofNew - month <= -2))
{
[tempNewsArray delete:[tempNewsArray objectAtIndex:i]];//exception occurs here.
//deleted
}
}

我想我遗漏了什么,请帮忙?

最佳答案

请试试这个,

int indexNum=-1;
NSMutableArray* tempNewsArray = [[NSMutableArray alloc]init];
tempNewsArray = [[defaults objectForKey:@"NewsArray"]mutableCopy];
for(int i = 0;i< [tempNewsArray count]-1;i++)
{
if( (monthIntofNew - month <= 10 && monthIntofNew - month !=0) || ( monthIntofNew - month <= -2))
{
indexNum=i;
//[tempNewsArray delete:[tempNewsArray objectAtIndex:i]];//exception occurs here.
//deleted
}
}

if(indexNum!=-1)
{
[tempNewsArray removeObjectAtIndex:indexNum];
}

希望对您有所帮助。

关于iOS删除表单可变数组异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20605835/

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