そのため、ボタンにカーソルを合わせるとポップアップウィンドウが表示されるボタン(ボタンである必要はありません)を備えたアプリケーションを作成しようとしています。ボタンにカーソルを合わせるとログにメッセージを出力できましたが、画像のHiddenプロパティをNOに設定する方法がわかりません。NSButtonCell(ホバーイベントを受信するクラス)にデリゲートを与えてみましたが、
[myButtonCell setDelegate:delegateObject]
オブジェクトにデリゲートを与えません。buttonCellと画像が通信する方法(両方とも同じxibにある)を見つけるか、buttonCellに、インスタンスとしてそれを持っているクラスの1つで関数を呼び出す方法を見つけることができれば、簡単に理解できます。残り。
私の説明は少し拡散しているので、もっとよく説明しようと思います。NSButtonCellオブジェクト(IBOutlet)のサブクラスを持つビューオブジェクトを持つウィンドウオブジェクトがあります。NSButtonCellのサブクラス(MyButtonCellと呼びます)には、呼び出し時にビューまたはウィンドウにメソッドが呼び出されたことを通知する必要があるメソッドがあります。
どこを見てもいい気がしますが、解決策が見つかりません。デリゲートで作成しようと思っていましたが、buttonCellのデリゲートを設定できないため、行き詰まりました…</ p>
編集:
NSButtonCellとデリゲートのコードは次のとおりです。デリゲート:
@interface MyView : NSView <MyButtonCellDelegate>
{
}
@property (assign) IBOutlet MyButtonCell *buttonCell1;
- (void)toggleField:(int)fieldID;
@end
@implementation MyView
- (void)toggleField:(int)fieldID
{
if (fieldID == 1) {
[self.field1 setHidden:!buttonCell1.active];
}
NSLog(@"toggling");
}
@end
MyButtonCell:
@protocol MyButtonCellDelegate
- (void)toggleField:(int)fieldID;
@end
@interface MyButtonCell : NSButtonCell
{
id <MyButtonCellDelegate> delegate;
}
@property BOOL active; //Used to lett the view know wether the mouse hovers over it
@property (nonatomic, assign) id <DuErButtonCellDelegate> delegate;
-(void)_updateMouseTracking; //mouse tracking function, if you know a better way to do it that would be lovely
@end
@implementation MyButtonCell
@synthesize delegate;
@synthesize active;
- (void)mouseEntered:(NSEvent *)event
{
active = YES;
[[self delegate] toggleField:1];
NSLog(@"entered");
}
- (void)mouseExited:(NSEvent *)event
{
active = NO;
[[self delegate] toggleField:1];
}
- (void)_updateMouseTracking {
[super _updateMouseTracking];
if ([self controlView] != nil && [[self controlView] respondsToSelector:@selector(_setMouseTrackingForCell:)]) {
[[self controlView] performSelector:@selector(_setMouseTrackingForCell:) withObject:self];
}
}
@end
これが十分に明確であることを願っています