2 developerwab developerWab 于 2013.04.01 15:23 提问

NSMutableArray 添加NSArray问题

不知道怎么使用NSMutableArrayNSArray

代码:

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"
    ))

不知道应该怎么实现。

1个回答

karas117
karas117   2013.04.01 16:36
已采纳
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];
        }
}
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!