gpt4 book ai didi

objective-c - NSOutlineView 没有做它在它的子类中应该做的事情

转载 作者:行者123 更新时间:2023-12-03 17:33:14 26 4
gpt4 key购买 nike

我创建了 NSOutlineView 的子类,并使用以下代码使行颜色交替。

头文件。

#import <Cocoa/Cocoa.h>


@interface MyOutlineView : NSOutlineView {
}

- (void) drawStripesInRect:(NSRect)clipRect;

@end

实现文件。

#import "MyOutlineView.h"

// RGB values for stripe color (light blue)
#define STRIPE_RED (237.0 / 255.0)
#define STRIPE_GREEN (243.0 / 255.0)
#define STRIPE_BLUE (254.0 / 255.0)
static NSColor *sStripeColor = nil;

@implementation MyOutlineView

// This is called after the table background is filled in,
// but before the cell contents are drawn.
// We override it so we can do our own light-blue row stripes a la iTunes.
- (void) highlightSelectionInClipRect:(NSRect)rect {
[self drawStripesInRect:rect];
[super highlightSelectionInClipRect:rect];
}

// This routine does the actual blue stripe drawing,
// filling in every other row of the table with a blue background
// so you can follow the rows easier with your eyes.
- (void) drawStripesInRect:(NSRect)clipRect {
NSRect stripeRect;
float fullRowHeight = [self rowHeight] + [self intercellSpacing].height;
float clipBottom = NSMaxY(clipRect);
int firstStripe = clipRect.origin.y / fullRowHeight;
if (firstStripe % 2 == 0)
firstStripe++; // we're only interested in drawing the stripes
// set up first rect
stripeRect.origin.x = clipRect.origin.x;
stripeRect.origin.y = firstStripe * fullRowHeight;
stripeRect.size.width = clipRect.size.width;
stripeRect.size.height = fullRowHeight;
// set the color
if (sStripeColor == nil)
sStripeColor = [[NSColor colorWithCalibratedRed:STRIPE_RED
green:STRIPE_GREEN
blue:STRIPE_BLUE
alpha:1.0] retain];
[sStripeColor set];
// and draw the stripes
while (stripeRect.origin.y < clipBottom) {
NSRectFill(stripeRect);
stripeRect.origin.y += fullRowHeight * 2.0;
}
}

@end

但问题是代码应该做的事情并没有发生在大纲 View 上,代码是正确的,但我是否需要通过某种方式将大纲 View 连接到代码?

最佳答案

如果您在IB中实例化大纲 View ,则需要在身份检查器中将大纲 View 的类名称设置为“MyOutlineView”。请记住双击该控件,以便选择内部矩形,并且检查器窗口标题为“Outline View Identity”;单击该控件只会选择 ScrollView ( ScrollView 中嵌入了轮廓 View )。

如果您以编程方式创建大纲 View ,请确保实例化 MyOutlineView 而不是 NSOutlineView:

MyOutlineView *outlineView = [[MyOutlineView alloc] initWithFrame:rect];

其中 rect 是大纲 View 的框架。

关于objective-c - NSOutlineView 没有做它在它的子类中应该做的事情,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/993465/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com