问题描述
- NSMutableArray 添加NSArray问题
- 不知道怎么使用
NSMutableArray
和NSArray
。代码:
for (int i=0; i<[DateSortArry2 count]; i++) { for (int j=0; j<[DateSortArry2Copy count]; j++) { NSString *sectiondateStr2 = [NSString stringWithFormat:@""%@""[DateSortArry2Copy objectAtIndex:j]]; if ([[DateSortArry2 objectAtIndex:i] isEqualToString:sectiondateStr2]) { [Arry addObject:sectiondateStr2]; } } [SumArry addObjectsFromArray:Arry]; [Arry removeAllObjects]; }
代码得到的结果:
SumArry:(20130227""20130227""20130227""20130226""20130226""20130226""20130225""20130225"")
要求的结果:
SumArry:((20130227""20130227""20130227"" ) (20130226""20130226""20130226"" ) (20130225""20130225"" ))
不知道应该怎么实现。
解决方案
NSString *str = @"""";for (int i=0; i<[DateSortArry2 count]; i++) { if (str isEqualToString:[DateSortArry2 objectAtIndex:i]) { return; } else { NSMutableArray * Arry = [[NSMutableArray alloc] init]; str = [DateSortArry2 objectAtIndex:i] for (int j=0; j<[DateSortArry2Copy count]; j++) { if ([[DateSortArry2 objectAtIndex:i] isEqualToString:str]) { [Arry addObject:str]; } } [SumArry addObject:Arry]; [Arry removeAllObjects]; }}
时间: 2024-11-20 16:06:39