NSOutlineView의 편집 가능한 셀을 만드는 방법을 알고있는 사람이 있습니까? 나는 사과에서 sampe 코드를 사용하여 나는 그것을 전혀 작동하지 않는 것.NSOutlineView 행을 편집 가능하게하기
NSOutlineView의 셀에서 빠르게 연속해서 두 번 클릭하면 셀이 편집 가능 해져 사용자가 셀 안의 텍스트를 업데이트 할 수 있도록 설정하려고합니다. (xcode에서 작동하는 것과 같은 방식으로, 그리고 메일 등).
나는이 컨트롤러의 나머지 코드 대부분을 내가 뭘 잘못하고 있는지를 알 수있는 헛된 희망으로 포함시키고있다. 매우 실망 스럽다. 두 번 클릭하면 NSLog 메시지를 반환하므로 shouldEditTableColumn
이 호출되고 있음을 알고 있습니다.
@implementation DisplayHierarchyController
- (void)awakeFromNib {
// cache the reused icon images
folderImage = [[[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kGenericFolderIcon)] retain];
[folderImage setSize:NSMakeSize(16,16)];
objectImage = [[[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kGenericPreferencesIcon)] retain];
[objectImage setSize:NSMakeSize(16,16)];
diagramImage = [[[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kGenericEditionFileIcon)] retain];
[diagramImage setSize:NSMakeSize(16,16)];
//
// Tell the outline view to use a special type of cell
//NSTableColumn *tableColumn = [[outline tableColumns] objectAtIndex: 0];
//ImageTextCell *imageTextCell = [[[ImageTextCell alloc] init] autorelease];
//[imageTextCell setEditable:YES];
//[tableColumn setDataCell:imageTextCell];
//
[[[outline tableColumns] objectAtIndex: 0] setEditable: YES];
}
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item {
NSLog(@"edit %@", tableColumn);
return YES;
}
- (NSCell *)outlineView:(NSOutlineView *)outlineView dataCellForTableColumn:(NSTableColumn *)tableColumn item:(id)item {
ImageTextCell *imageTextCell = [[[ImageTextCell alloc] init] autorelease];
[imageTextCell setEditable:YES];
return imageTextCell;
}
// Returns the object that will be displayed in the tree
- (id)outlineView: (NSOutlineView *)outlineView child: (int)index ofItem: (id)item {
if(item == nil)
return [[document children] objectAtIndex: index];
if([item isKindOfClass: [Item class]])
return [[item children] objectAtIndex: index];
return document;
}
- (BOOL)outlineView: (NSOutlineView *)outlineView isItemExpandable: (id)item {
if([item isKindOfClass: [Item class]])
return [[item children] count]>0;
return NO;
}
- (int)outlineView: (NSOutlineView *)outlineView numberOfChildrenOfItem: (id)item {
if(item == nil)
return document.children.count;
if([item isKindOfClass: [Item class]])
return [[item children] count];
return 0;
}
- (id)outlineView: (NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
if([item isKindOfClass: [Item class]])
return [item name];
return @"n/a";
}
- (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
NSLog(@"setObjectValue called");
}
- (void)outlineView:(NSOutlineView *)olv willDisplayCell:(NSCell*)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item {
[cell setEditable: YES];
[cell setAllowsEditingTextAttributes: YES];
[(ImageTextCell*)cell setImage: objectImage];
}
- (BOOL)control:(NSControl *)control textShouldBeginEditing:(NSText *)fieldEditor {
return YES;
}
- (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor {
if ([[fieldEditor string] length] == 0) {
// don't allow empty node names
return NO;
} else {
return YES;
}
}
@end
"전혀 작동하지 않는 것 같습니다."이 뜻은 무엇입니까? 보다 구체적으로 질문을 수정하십시오. –
잘하면 그게 명확하게. 행을 두 번 클릭하면 그 행을 편집 할 수 있습니다. – Jacob
이 작업을 수행하는 방법에 대한 더 많은 연구를하고 있습니다. Apple 설명서에서 "개요보기는 상위 클래스 인 NSTableView에서 그 동작을 대부분 상속받습니다. 자세한 내용은 Table View 프로그래밍 가이드를 참조하십시오. " NSTableView는이 메소드를 가지고 있습니다. "(BOOL) tableView : (NSTableView *) aTableView shouldEditTableColumn : (NSTableColumn *) aTableColumn row : (NSInteger) rowIndex"그러나 나는 그것을 얻는 방법으로 컨트롤러에 추가 할 수없는 것 같습니다 라는. – Jacob