NSArray에 정의 된 정적 인 변경되지 않는 구조로 NSOutlineView를 구현하기에 충분한 지식 스 니펫을 함께 모으는 데 어려움을 겪고 있습니다. This link은 훌륭했지만 하위 메뉴를 파악하는 데 도움이되지 않습니다. 나는 그들이 단지 NSArrays를 중첩 시킨다고 생각하지만, 나는 명확한 생각이 없다. objectValueForTableColumn :정적 NSOutlineView 구현
의 우리가 텍스트가 outlineView에 정의되어
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];
로 정의 된 NSArray를 내부에있는 NSArray, 있다고 가정 해 봅시다 byItem을 :.
는- (id)outlineView:(NSOutlineView *)ov objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)ovItem
{
if ([[[tableColumn headerCell] stringValue] compare:@"Key"] == NSOrderedSame)
{
// Return the key for this item. First, get the parent array or dictionary.
// If the parent is nil, then that must be root, so we'll get the root
// dictionary.
id parentObject = [ov parentForItem:ovItem] ? [ov parentForItem:ovItem] : ovStructure;
if ([parentObject isKindOfClass:[NSArray class]])
{
// Arrays don't have keys (usually), so we have to use a name
// based on the index of the object.
NSLog([NSString stringWithFormat:@"%@", ovItem]);
//return [NSString stringWithFormat:@"Item %d", [parentObject indexOfObject:ovItem]];
return (NSString *) [ovStructure objectAtIndex:[ovStructure indexOfObject:ovItem]];
}
}
else
{
// Return the value for the key. If this is a string, just return that.
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를 사용하여 시도 :..하지만 결과를 비교하기 위해 무엇을 알아낼 수
나는 무엇 실종
중첩 된 속성 목록은 고통에 대한 확실한 경로입니다. 일반적으로 모델 객체를 만들고 대신 사용해야합니다. http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ModelObjects/ 또한 현재 언어에 따라 변경되어야하는 열 머리글의 제목을 보지 마십시오. 앱); 대신 열의 식별자를 사용하십시오. –