NSOutlineViewの編集可能なセルを作成する方法を知っている人はいますか?私はリンゴからsampeコードを使用して、私はそれはまったく動作するように思わない。NSOutlineViewの行を編集可能にする
NSOutlineViewのセルで2回連続して2回クリックすると、セルが編集可能になり、ユーザーがセル内のテキストを更新できるように設定しようとしています。 (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
これを動作させる方法をさらに研究しています。アップルのドキュメントでは、「アウトラインビューは親クラスNSTableViewからの動作の多くを継承しています。詳細は、「Table Viewプログラミングガイド」を参照してください。 NSTableViewはこのメソッドを持っています "(BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn行:(NSInteger)rowIndex"しかし、私はそれが私のコントローラにそれが取得する方法で追加することはできないようですと呼ばれる。 – Jacob