-1

我有一棵树NSMutableArray作为treeChannelModel.data,我想生成NSMutableArraytreeChannelModel.data的树级别。例如我想获得树级别:

NSMutableArray= {0,1,2,2,2,2,2,2,0,1,2,2,2,2,2,3,3,2,2,2,2,3,2,1,2,3,3,2,1,2,3,3,3,2,3,3,2,3,3,3,2,3,2,3,2,3,2,3,2,3,2,3};

NSMutableArray *depths1 = [NSMutableArray array];
for(int i=0;i<treeChannelModel.data.count;i++){
    depths1=[self ChildIntRecursiveWithChannels:channels depths:depths1 number:0];
}

- (NSMutableArray *)ChildIntRecursiveWithChannels:(Channels *)channels  depths:(NSMutableArray *) depths number:(int)number {
    number+=1;
    [ depths addObject:[NSNumber numberWithInt:number]];

    if(channels.channels.count>0){
        for(int i=0;i<channels.channels.count;i++){
            [self ChildIntRecursiveWithChannels:channels depths:depths number:number];
        }
    }
    return  depths;
}

但我得到一个不正确的数组。你能给点建议吗

4

1 回答 1

0
- (NSMutableArray *)ChildIntRecursiveWithChannels:(Channels *)channels
                                           depths:(NSMutableArray *)depths
                                           number:(int)number {

    [depths addObject:[NSNumber numberWithInt:number]];
    number += 1;

    NSLog(@"channels.channels.name:%@", channels.name);

    for(int i = 0; i < channels.channels.count; i++){
        [self ChildIntRecursiveWithChannels:channels.channels[i] depths:depths number:number];
    }
    return  depths;
}
于 2013-04-28T06:50:54.170 回答