Objective c NSOutlineView显示三个级别
我正在使用NSOutlineView,我想显示第四个子级别。现在我只能显示三个子级别 大纲视图控制器.mObjective c NSOutlineView显示三个级别,objective-c,xcode,cocoa,nsoutlineview,Objective C,Xcode,Cocoa,Nsoutlineview,我正在使用NSOutlineView,我想显示第四个子级别。现在我只能显示三个子级别 大纲视图控制器.m -(id)init{ self = [super init]; if(self){ _people = [[NSMutableArray alloc]init]; Person *quick = [[Person alloc]initWithName:@"First"]; [quick addChild:[[Per
-(id)init{
self = [super init];
if(self){
_people = [[NSMutableArray alloc]init];
Person *quick = [[Person alloc]initWithName:@"First"];
[quick addChild:[[Person alloc]initWithName:@"Second"]];
[(Person *)[quick.children objectAtIndex:0]addChild:[[Person alloc]initWithName:@"Third"]];
[_people addObject:quick];
}
return self;
}
人
-(id)init{
return [self initWithName:@"Name"];
}
-(id)initWithName:(NSString *)name {
self = [super init];
if(self){
_name = [name copy];
_children = [[NSMutableArray alloc]init];
}
return self;
}
-(void)addChild:(Person *)p {
[_children addObject:p];
}
人
@property (copy)NSString *name;
@property(readonly,copy)NSMutableArray *children;
-(id)initWithName:(NSString *)name;
-(void)addChild:(Person *)p;
我得到的输出是这样的
>First
>Second
Third
我想要这样的输出
>First
>Second
>Third
>Fourth
Fifth
谢谢。您将在此处向second添加一个孩子:
[(Person *)[quick.children objectAtIndex:0]addChild:[[Person alloc]initWithName:@"Third"]];
类似地,您可以将子项添加到第三项:
[(Person*)[((Person *)[quick.children objectAtIndex:0]).children objectAtIndex:0]addChild:[[Person alloc]initWithName:@"Fourth"]];
然后是第四个:
[(Person*)[((Person*)[((Person *)[quick.children objectAtIndex:0]).children objectAtIndex:0]).children objectAtIndex:0] addChild:[[Person alloc]initWithName:@"Fifth"]];
或者,为了简单起见,首先创建最低级别的对象,然后将其作为子对象添加到其父对象:
Person *fifth = [[Person alloc]initWithName:@"Fifth"];
Person *fourth = [[Person alloc]initWithName:@"Fourth"];
[fourth addChild: fifth];
Person *third = [[Person alloc]initWithName:@"Third"];
[third addChild: fourth];
Person *second = [[Person alloc]initWithName:@"Second"];
[second addChild: third];
Person *quick = [[Person alloc]initWithName:@"First"];
[quick addChild: second];
你要加三个孩子,这就是为什么你要加三级,再加一个孩子到第三级,再到第四级我知道怎么把孩子加到第三级?