Getting around IBActions limited scope
Posted
by Septih
on Stack Overflow
See other posts from Stack Overflow
or by Septih
Published on 2010-05-18T14:11:35Z
Indexed on
2010/05/20
9:40 UTC
Read the original article
Hit count: 295
Hello,
I have an NSCollectionView and the view is an NSBox with a label and an NSButton. I want a double click or a click of the NSButton to tell the controller to perform an action with the represented object of the NSCollectionViewItem. The Item View is has been subclassed, the code is as follows:
#import <Cocoa/Cocoa.h>
#import "WizardItem.h"
@interface WizardItemView : NSBox {
id delegate;
IBOutlet NSCollectionViewItem * viewItem;
WizardItem * wizardItem;
}
@property(readwrite,retain) WizardItem * wizardItem;
@property(readwrite,retain) id delegate;
-(IBAction)start:(id)sender;
@end
#import "WizardItemView.h"
@implementation WizardItemView
@synthesize wizardItem, delegate;
-(void)awakeFromNib {
[self bind:@"wizardItem" toObject:viewItem withKeyPath:@"representedObject" options:nil];
}
-(void)mouseDown:(NSEvent *)event {
[super mouseDown:event];
if([event clickCount] > 1) {
[delegate performAction:[wizardItem action]];
}
}
-(IBAction)start:(id)sender {
[delegate performAction:[wizardItem action]];
}
@end
The problem I've run into is that as an IBAction, the only things in the scope of -start are the things that have been bound in IB, so delegate and viewItem. This means that I cannot get at the represented object to send it to the delegate.
Is there a way around this limited scope or a better way or getting hold of the represented object?
Thanks.
© Stack Overflow or respective owner