Link to home
Start Free TrialLog in
Avatar of Kostja Paschalidis
Kostja Paschalidis

asked on

NSButton cannot setaction

I am trying to add an action to a NSButton but it is not working

I create my NSButtton programmatically:

-(NSView *)rowTable:(CGFloat) heightOnPanel :(NSString *) textValue: (CGFloat) width: (CGFloat) height :(int) intColor{
    NSView *viewce = [[NSView alloc] initWithFrame:CGRectMake(0, heightOnPanel, 320, 40)];
    NSButton *layerBt = [[NSButton alloc] initWithFrame:NSMakeRect(0, 0, width, height)];

    [layerBt setTitle:textValue];

    [layerBt setButtonType:NSMomentaryPushInButton];
    [layerBt setTarget:nil];
    [layerBt setAction:@selector(buttonPressed:)];
    [viewce addSubview:layerBt];

    return viewce;
}

Open in new window



and here is IBAction method:


- (IBAction)buttonPressed:(id) sender{
    NSLog(@"hello world");
}

Open in new window


Could you point me to what I am missing?

Thanks
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.