GVKun编程网logo

objective-c – 使NSOutlineView行可编辑(clistctrl可编辑行)

21

以上就是给各位分享objective-c–使NSOutlineView行可编辑,其中也会对clistctrl可编辑行进行解释,同时本文还将给你拓展objective-c–NSButton中的图像和NS

以上就是给各位分享objective-c – 使NSOutlineView行可编辑,其中也会对clistctrl可编辑行进行解释,同时本文还将给你拓展objective-c – NSButton中的图像和NSImageView模糊、objective-c – NSImageView圆角笔划、objective-c – NSImageView背景颜色、objective-c – NSOutlineView中的NSView层等相关知识,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

objective-c – 使NSOutlineView行可编辑(clistctrl可编辑行)

objective-c – 使NSOutlineView行可编辑(clistctrl可编辑行)

有没有人知道如何在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 – NSButton中的图像和NSImageView模糊

objective-c – NSButton中的图像和NSImageView模糊

我完全被这里难住;我有一系列小图像,我正在修补和制作按钮:

正如你所看到的那样,它们都非常清晰锐利,并且在我打开预览中的png文件时保留了这一点.

但是,当我在Interface Builder中的NSButtons和NSImageViews中使用它们时,将Scaling设置为None:

图像变得非常模糊.我究竟做错了什么?我不知道从哪里开始和尝试什么;我应该回到图标并尝试让它们像素完美吗?它是否与抗锯齿或沿着这些线的东西有关?

编辑:
出于某种原因,似乎NSButtons和NSImageViews正在加载图像的高分辨率版本,即使我在正常显示器上,可以通过我添加到它们的轻微浅蓝色笔划来识别.出于某种原因,Quartz Debug不会将这些识别为高分辨率图像,并且没有红色调.删除对@ 2x图像的引用确实解决了问题……但……

解决方法

如果您在WWSI 2012视频中查看会话245,请参阅NSImage第一部分中关于OS X高分辨率的高级提示和技巧,您将找到原因.

NSImage没有任何高分辨率的概念 – 它只使用比它必须填充的空间更多的像素的最小图像 – 所以如果您的NSImageView尺寸大于1x图像,它将使用2x图像,因为它具有更多像素.

objective-c – NSImageView圆角笔划

objective-c – NSImageView圆角笔划

我有子类NS ImageView,我想用圆角绘制边框.它工作,但我也需要剪掉图像的角落.

请看我的截图:

我创建了这个代码来绘制边框/角落.

- (void)drawRect:(NSRect)dirtyRect
{
    [super drawRect:dirtyRect];

    NSColor *strokeColor;
    if(self.isSelected)
        strokeColor = [NSColor colorFromHexRGB:@"f9eca2"];
    else
        strokeColor = [NSColor colorFromHexRGB:@"000000"];

    [strokeColor set];    
    [[NSBezierPath bezierPathWithRoundedRect:NSInsetRect(dirtyRect,1,1) xRadius:5 yRadius:5] stroke];
}

我应该怎么做图像剪辑?

编辑:

我修好了,但我觉得这是一种丑陋的方式.还有什么更聪明的吗?

新代码:

- (void)drawRect:(NSRect)dirtyRect
{
    NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:NSInsetRect(dirtyRect,2,2) xRadius:5 yRadius:5];

    [path setlinewidth:4.0];
    [path addClip];

    [self.image drawAtPoint: NSZeroPoint
                 fromrect:dirtyRect
                 operation:NSCompositeSourceOver
                 fraction: 1.0];

    [super drawRect:dirtyRect];

    NSColor *strokeColor;
    if(self.isSelected)
    {
        strokeColor = [NSColor colorFromHexRGB:@"f9eca2"];
    }
    else
        strokeColor = [NSColor colorFromHexRGB:@"000000"];

    [strokeColor set];    
    [NSBezierPath setDefaultlinewidth:4.0];
    [[NSBezierPath bezierPathWithRoundedRect:NSInsetRect(dirtyRect,2) xRadius:5 yRadius:5] stroke];
}

解决方法

将NSImageViews图层的圆角半径也设置为5像素,并将其maskToBounds属性设置为YES.

objective-c – NSImageView背景颜色

objective-c – NSImageView背景颜色

我有这样的要求,

有一个NSIMageView,它会在定时器的基础上频繁更改,在调整大小时,它需要保持宽高比,所以Image可能不会占用Image的整个帧,在这种情况下,我需要显示背景颜色为黑色,

任何人都可以帮助我,我怎么能实现这一点,谷歌搜索有一种方法是拥有NSImageView的SubClass,但不知道,会对性能产生什么影响,因为图像经常变化,

解决方法

将图像视图的大小调整模式设置为“比例”.将它封装在一个设置为自定义模式的NSBox中,背景为黑色.不需要代码,只是在盒子里面思考……

objective-c – NSOutlineView中的NSView层

objective-c – NSOutlineView中的NSView层

我正在尝试创建一个自定义NSView,托管CALayer层次结构以执行高效显示.然后将NSView嵌入到由基于视图的NSOutlineView显示的NSTableCellView中.

问题是,每当我展开或折叠一个项目时,所有行都被移动,但是图层的内容仍然显示在更改大纲之前的位置.

滚动NSOutlineView似乎刷新了这些图层,并在这一点上重新同步它们的行.

我已经使用仪器调试了这种行为,似乎滚动引发了一个布局操作,它使用setPosition:调用来更新层,这些调用在展开或折叠项目时应该发生.

以下是一个承载NSView子类的简单图层的示例代码.

@interface TestView : NSView

@end

@implementation TestView

- (instancetype)initWithFrame:(NSRect)frameRect
{
    self = [super initWithFrame:frameRect];
    CAShapeLayer* layer = [CAShapeLayer layer];
    layer.bounds = self.bounds;
    layer.position = CGPointMake(NSMidX(self.bounds),NSMidY(self.bounds));
    layer.path = [NSBezierPath bezierPathWithovalInRect:self.bounds].CGPath;
    layer.fillColor = [NSColor redColor].CGColor;
    layer.delegate = self;
    self.layer = layer;
    self.wantsLayer = YES;
    return self;
}

@end

我已经尝试了很多潜在的解决方案,但我找不到任何有趣的方法被调用在NSView实例,可以覆盖调用[self.layer setNeedsdisplay]或[self.layer setNeedsLayout].我也在CALayer本身尝试过各种设置器,如:

layer.autoresizingMask = kCALayerWidthSizable | kCALayerHeightSizable;
layer.needsdisplayOnBoundsChange = YES;
self.layerContentsRedrawPolicy = NSViewLayerContentsRedrawOnSetNeedsdisplay;

任何人都可以帮我弄清楚如何使这个层在NSOutlineView内正常显示?

解决方法

我最后回答了我的问题.问题不在于我的TestView实现方式.我简单地错过了在应用程序中启用CoreAnimation支持的步骤之一.相关参考文献在“核心动画编程指南”中.

基本上,在iOS Core Animation和layer-backing中始终默认启用.在OS X上,必须以这种方式启用:

>链接到QuartzCore框架
>通过执行以下操作之一为一个或多个NSView对象启用图层支持

>在您的nib文件中,使用View Effects检查器为视图启用图层支持.检查员将显示所选视图及其子视图的复选框.建议您尽可能在窗口的内容视图中启用图层支持
>对于以编程方式创建的视图,请调用视图的setWantsLayer:方法,并传递值为YES以指示视图应使用图层.

一旦在任何NSOutlineView的父母上启用了图层支持,就会解决各种故障.

今天关于objective-c – 使NSOutlineView行可编辑clistctrl可编辑行的介绍到此结束,谢谢您的阅读,有关objective-c – NSButton中的图像和NSImageView模糊、objective-c – NSImageView圆角笔划、objective-c – NSImageView背景颜色、objective-c – NSOutlineView中的NSView层等更多相关知识的信息可以在本站进行查询。

本文标签: