【发布时间】:2013-02-25 01:36:14
【问题描述】:
我正在尝试创建一个包含播放/暂停按钮的自定义视图,我会将任意数量的这些按钮附加到 NSWindow。我首先创建自己的 NSView 并绘制出各个部分,然后将播放/暂停按钮子类化为 NSView(小步骤)。
这一切都很好,直到我决定我的按钮需要扩展 NSButtonCell 而不是 NSView。以下(来自 TimeSlipView.m)惨遭失败,我似乎无法弄清楚原因:
playPauseButton = [[TimeSlipViewButton alloc] init];
[playPauseButton setButtonType:NSMomentaryPushInButton];
[self addSubview:playPauseButton];
最后一行出现编译错误和警告:“不兼容的指针类型将'TimeSlipViewButton *__strong'发送到'NSView *'类型的参数”。
我感觉我误解了一些非常基本的东西,出于某种原因,我不能只从 NSView 中传递 addSubview: 我的 NSButtonCell。
TimeSlipView.h
#import <Cocoa/Cocoa.h>
#import "TimeSlipViewButton.h"
@interface TimeSlipView : NSView {
TimeSlipViewButton *playPauseButton;
NSView *timerText;
NSView *clientText;
NSView *projectText;
NSView *taskText;
}
@end
TimeSlipViewButton.h
#import <Cocoa/Cocoa.h>
@interface TimeSlipViewButton : NSButtonCell
@end
【问题讨论】:
标签: objective-c cocoa