nsbutton performClick not working

749 views Asked by At

I have an NSButton btnOne and when the user clicks on the button, I want to simulate a click on another button btnTwo. btnTwo has an action which displays a message when clicked.

- (IBAction)btnOneClicked:(id)sender
{
    [btnTwo performClick:self];
}

- (IBAction)btnTwoClicked:(id)sender
{
    NSLog(@"btnTwo clicked");
}

When I run the program and click on btnOne, the performClick does not seem to simulate the click on btnTwo as no message is displayed.

I've also tried overriding the performClick() of btnTwo in an NSButton subclass to display the message.

-(void)performClick:(id)sender
{
   NSLog(@"performClick"); 
}

This is also not happening. The message is not getting displayed.

What am I doing wrong?

Thanks.

2

There are 2 answers

0
Ashish Rana On

I used in my on going project. And it worked for me.

self.perform(#selector(HomeViewController.startCapure(_:)), with: self.btnStart)
0
Andreas Utzinger On

I know it's a late answer, but better late then never, right? :)

add

[super performClick:sender]

at the end of your overridden performClick method.

Why it doesn't call the action method in the first place (without overriding performClick) is a thing that can have many problems. Are the buttons connected to their action methods?