我试图从我的数组中删除一些东西,但我得到了异常
删除时无法识别的选择器
我的代码:
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]; }
希望这会帮助你.