Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSButton Multiple clicks

I have an IBAction of when the button is clicked to change my view. How can I handle multiple clicks for example if I click the button a second time to cause another action?

Or do I need to delete the button after it has been clicked and then create a new one in its place? If so how do I handle the click event?

like image 392
Grant Wilkinson Avatar asked Jun 24 '26 06:06

Grant Wilkinson


2 Answers

You can check the clickCount of the mouseDown event:

if ([event clickCount] > 1)
{
    // ... do double-click action
}
else
{
    // ... do single-click action
}
like image 65
user1118321 Avatar answered Jun 27 '26 04:06

user1118321


You can add NSClickGestureRecognizer to the desired view from the storyboard Library as seen below

Click getsure in library

You can simply drag an IBAction from this object to the View controller


The Attributes inspector will provide you with many useful options like Number of clicks that should match and button masks

enter image description here

like image 28
Kaunteya Avatar answered Jun 27 '26 04:06

Kaunteya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!