Search code examples
objective-ccocoanstimeribaction

How to have make a button disable a action (cocoa)


I'm wondering if there is a way to disable a IBAction from a button. Basically I'm setting an NSTimer so that the application will close in 10 seconds in the applicationDidFinishLaunching, but when you push a button it will cancel that timer and the application will stay open. Is there any way to do this? Ive tried a very bad way and did a NSTimer when a NSButton (checkbox) was checked but when you push the button it would disable the checkbox and the timer. i want to know the programmatically way of doing this, thanks in advance. (ON OS X COCOA)


Solution

  • Not sure I understand correctly, but you can disable button programmatically with

    [myButton setEnabled:NO];
    

    It will disable the button so it will be impossible to fire IBAction.

    Or you can remove action from a button with

    [myButton setAction:nil]