objective-c – 使NSOutlineView行可编辑

objective-c – 使NSOutlineView行可编辑,第1张

概述有没有人知道如何在NSOutlineView的可编辑中制作单元格?我使用苹果的样本代码,我似乎无法让它工作. 我正在设置它,以便当您在NSOutlineView中的单元格上快速连续单击两次时,单元格变为可编辑,以便用户可以更新单元格内的文本. (与xcode和邮件等工作方式相同). 我包含了这个控制器的大部分代码,徒劳地希望有人可以发现我做错了什么,这是非常令人沮丧的.我知道调用了theEditT 有没有人知道如何在NSOutlineVIEw的可编辑中制作单元格?我使用苹果的样本代码,我似乎无法让它工作.

我正在设置它,以便当您在NSOutlineVIEw中的单元格上快速连续单击两次时,单元格变为可编辑,以便用户可以更新单元格内的文本. (与xcode和邮件等工作方式相同).

我包含了这个控制器的大部分代码,徒劳地希望有人可以发现我做错了什么,这是非常令人沮丧的.我知道调用了theEdittableColumn,因为它在双击时返回NSLog消息.

@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
解决方法 我知道这是一篇非常古老的帖子,但如果有人遇到同样的问题,这可能不是与代码相关的问题.对于我的情况,这是一个与XIB本身的值集相关的问题.

因此,假设您已经复制了所有Apple代码,并且您已经启动并运行了NSOutlineVIEw,以及一些仍然无法编辑的内容,请转到您的XIB并设置您想要的单元格的NSTextFIEld的以下设置编辑.在我的情况下,行为设置默认设置为none.也许对你来说也是同样的问题

干杯.

总结

以上是内存溢出为你收集整理的objective-c – 使NSOutlineView行可编辑全部内容,希望文章能够帮你解决objective-c – 使NSOutlineView行可编辑所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1008338.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存