我很难收集到足够多的知识片段来实现一个静态的、永不改变的NSarray中定义的结构的nsOutlineView。
This link
已经很好了,但它不能帮助我掌握子菜单。我想它们只是嵌套的NSarray,但我不清楚。
假设我们在一个NSARRAY中有一个NSARRAY,定义为
NSArray *subarray = [[NSArray alloc] initWithObjects:@"2.1", @"2.2", @"2.3", @"2.4", @"2.5", nil];
NSArray *ovStructure = [[NSArray alloc] initWithObjects:@"1", subarray, @"3", nil];
文本在OutlineView:ObjectValueForTableColumn:ByItem:中定义。
- (id)outlineView:(NSOutlineView *)ov objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)ovItem
{
if ([[[tableColumn headerCell] stringValue] compare:@"Key"] == NSOrderedSame)
{
id parentObject = [ov parentForItem:ovItem] ? [ov parentForItem:ovItem] : ovStructure;
if ([parentObject isKindOfClass:[NSArray class]])
{
NSLog([NSString stringWithFormat:@"%@", ovItem]);
return (NSString *) [ovStructure objectAtIndex:[ovStructure indexOfObject:ovItem]];
}
}
else
{
if ([ovItem isKindOfClass:[NSString class]])
{
return ovItem;
}
else if ([ovItem isKindOfClass:[NSDictionary class]])
{
return [NSString stringWithFormat:@"%d items", [ovItem count]];
}
else if ([ovItem isKindOfClass:[NSArray class]])
{
return [NSString stringWithFormat:@"%d items", [ovItem count]];
}
}
return nil;
}
结果是'1'、'('(可展开)和'3'。nslog显示以“(”开头的数组,因此是第二个项。扩展它会导致崩溃,因为超出了界限。我尝试使用parentforitem:但无法找到将结果与之进行比较的方法。
我错过了什么?