我有一棵树NSMutableArray
作为treeChannelModel.data,我想生成NSMutableArray
treeChannelModel.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;
}
但我得到一个不正确的数组。你能给点建议吗