IOS

每一次循环中把rowsVideoFileChapter变量结果赋给一个rowsVideoFile字典对象后没有清空,导致后面循环中又不断地增加,但是添加removeAllObject过后章节的类容都没有了。
 NSMutableArray *rowsVideoFileChapter = [[NSMutableArray alloc]init];
    NSMutableArray *rowsVideoFile = [[NSMutableArray alloc]init];   //rowsVideoFileChapter =NULL;
    for(NSInteger iTemp1 = 1; iTemp1 <= 4; iTemp1++) {
         
        for (NSInteger iTemp11 = 1; iTemp11 <= 4; iTemp11++) {
            
            [rowsVideoFileChapter addObject:[[NSDictionary alloc] initWithObjectsAndKeys:@"1001", @"id",[NSString stringWithFormat:@"第%i章节",iTemp11] , @"title",@"60", @"position",nil]];
        
        }
                
        [rowsVideoFile addObject:[[NSDictionary alloc] initWithObjectsAndKeys:@"9347",@"id",[NSString stringWithFormat:@"第%i章节",iTemp1] ,@"title",@"9348-2224565.flv",@"video_path",rowsVideoFileChapter,@"rowsVideoFileChapter" ,nil]];            }    NSLog(@"rowsVideoFile=%@",rowsVideoFile);为什么[rowsVideoFileChapter removeAllObject]会导致之后赋值到rowsVideoFile里的rowsVideoFileChapter的内容都会清除?
如果用removeAllObject无法实现这个功能,那么还能用什么来得到这样的结果:
        id = 9347;
        rowsVideoFileChapter =         (
                        {
                id = 1001;
                position = 60;
                title = "\U7b2c1\U7ae0\U8282";
            },
                        {
                id = 1001;
                position = 60;
                title = "\U7b2c2\U7ae0\U8282";
            },
                        {
                id = 1001;
                position = 60;
                title = "\U7b2c3\U7ae0\U8282";
            },
                        {
                id = 1001;
                position = 60;
                title = "\U7b2c4\U7ae0\U8282";
            }
                    
        );
        title = "\U7b2c1\U7ae0\U8282";
        "video_path" = "9348-2224565.flv";
    }
 id = 9347;
        rowsVideoFileChapter =         (
                        {
                id = 1001;
                position = 60;
                title = "\U7b2c1\U7ae0\U8282";
            },
                        {
                id = 1001;
                position = 60;
                title = "\U7b2c2\U7ae0\U8282";
            },
                        {
                id = 1001;
                position = 60;
                title = "\U7b2c3\U7ae0\U8282";
            },
                        {
                id = 1001;
                position = 60;
                title = "\U7b2c4\U7ae0\U8282";
            }
                    
        );
        title = "\U7b2c2\U7ae0\U8282";
        "video_path" = "9348-2224565.flv";
    } id = 9347;
        rowsVideoFileChapter =         (
                        {
                id = 1001;
                position = 60;
                title = "\U7b2c1\U7ae0\U8282";
            },
                        {
                id = 1001;
                position = 60;
                title = "\U7b2c2\U7ae0\U8282";
            },
                        {
                id = 1001;
                position = 60;
                title = "\U7b2c3\U7ae0\U8282";
            },
                        {
                id = 1001;
                position = 60;
                title = "\U7b2c4\U7ae0\U8282";
            }
                    
        );
        title = "\U7b2c3\U7ae0\U8282";
        "video_path" = "9348-2224565.flv"; id = 9347;
        rowsVideoFileChapter =         (
                        {
                id = 1001;
                position = 60;
                title = "\U7b2c1\U7ae0\U8282";
            },
                        {
                id = 1001;
                position = 60;
                title = "\U7b2c2\U7ae0\U8282";
            },
                        {
                id = 1001;
                position = 60;
                title = "\U7b2c3\U7ae0\U8282";
            },
                        {
                id = 1001;
                position = 60;
                title = "\U7b2c4\U7ae0\U8282";
            }
                    
        );
        title = "\U7b2c4\U7ae0\U8282";
        "video_path" = "9348-2224565.flv";
    }
    }
)

解决方案 »

  1.   

    亲,[rowsVideoFileChapter removeAllObject]你加在哪里
      

  2.   


        NSMutableArray *rowsVideoFile = [[NSMutableArray alloc]init];   //rowsVideoFileChapter =NULL;
        for(NSInteger iTemp1 = 1; iTemp1 <= 4; iTemp1++) {
             NSMutableArray *rowsVideoFileChapter = [[NSMutableArray alloc]init];
            for (NSInteger iTemp11 = 1; iTemp11 <= 4; iTemp11++) {
                
                [rowsVideoFileChapter addObject:[[NSDictionary alloc] initWithObjectsAndKeys:@"1001", @"id",[NSString stringWithFormat:@"第%i章节",iTemp11] , @"title",@"60", @"position",nil]];
            
            }
            亲,你是想这样实现么
            [rowsVideoFile addObject:[[NSDictionary alloc] initWithObjectsAndKeys:@"9347",@"id",[NSString stringWithFormat:@"第%i章节",iTemp1] ,@"title",@"9348-2224565.flv",@"video_path",rowsVideoFileChapter,@"rowsVideoFileChapter" ,nil]];            }