iOS删除表单可变数组异常

 葉_沛峰 发布于 2023-02-10 11:25

我试图从我的数组中删除一些东西,但我得到了异常

删除时无法识别的选择器

我的代码:

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
    }
}

我想我错过了什么,请帮忙吗?

1 个回答
  • 请试试这个,

    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];
    }
    

    希望这会帮助你.

    2023-02-10 11:27 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有