iOS删除表单可变数组异常

标签 ios nsmutablearray

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

无法识别的选择器 在删除

我的代码:

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/

相关文章:

ios - 反向 NSMutableArray

html - 通过灯箱形式点击进入iPhone 6输入区,灯箱跳转页面

ios - 网址链接之间的空白

ios - 无法在模拟器中模拟MMWormhole应用程序

ios - 如何从 NSMutableArray 中删除 ID 对象?

ios - 将NSString对象添加到我的NSMutableArray时出错

objective-c - 访问数组中的元素 - 请求非结构或联合中的成员

ios - 使用 sendAsynchronousRequest :queue:completionHandler: 时显示 'data loading'

ios - 如何使用 setImage 将 NSMutableArray 中的 UIImage 添加到 UIButton

ios - 包含字典的数组的文件