Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6994859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:56:46+00:00 2026-05-27T19:56:46+00:00

Newbie Warning I have a simple but vexing problem trying to disable an NSButton.

  • 0

Newbie Warning

I have a simple but vexing problem trying to disable an NSButton. Here is sample code to illustrate the problem:

- (IBAction)taskTriggeredByNSButtonPress:(id)sender {
[ibOutletToNSButton setEnabled:NO];
//A task is performed here that takes some time, during which time
//the button should not respond to presses.
//Once the task is completed, the button should become responsive again.
[ibOutletToNSButton setEnabled:YES];
}

This is what I observe. I press the button. The button becomes disabled (judging by its faded appearance), and the task begins executing. While the button is disabled and the task is executing, I press the button a second time. Nothing happens immediately, but once the task is completed, the taskTriggeredByNSButtonPress: method is called a second time, suggesting that the second button press was placed on hold and then activated once the button became re-enabled.

I’ve tried all kinds of hacks to prevent the second button press from being recognized, including introducing a time delay after the [ibOutletToNSButton setEnabled:NO]; statement, making the button hidden rather than disabled, covering the button with a custom view during the time it should be disabled, binding the button’s enabled status to a property, and other things I’m too embarrassed to mention.

Please help me understand why I can’t get this simple task of disabling the button to work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:56:47+00:00Added an answer on May 27, 2026 at 7:56 pm

    This method seems to be directly linked to the button. You should perform the long action on another thread, or the main runloop won’t be available until the method returns. The main runloop doesn’t respond to events while it’s not available.

    First, create a method:

    - (void)someLongTask: (id)sender {
        // Do some long tasks…
    
        // Now re-enable the button on the main thread (as required by Cocoa)
        [sender performSelectorOnMainThread: @selector(setEnabled:) withObject: YES waitUntilDone: NO];
    }
    

    Then, perform that method in a separate thread when the button’s clicked:

    - (IBAction)buttonPushed: (id)sender {
        [sender setEnabled: NO];
        [self performSelectorInBackground: @selector(someLongTask) withObject: nil];
    }
    

    You may replace self in the example above with the object where -someLongTask resides.

    By multi-threading, you leave the main runloop alone and stable. Maybe, your problem will be solved. Otherwise, you solved a problem with responsiveness.

    (By the way, if the method is only called by the button, the sender argument is set to the button. That way, you don’t need to use an outlet in the method. But that’s just a hint.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a newbie. I have written some code for UITable but I am
(Warning - asp newbie) I have an aspx file with the tag <%@ Page
First, fair warning: I am a complete newbie with C# and WPF. I have
I'm a complete WinDbg newbie and I've been trying to debug a WindowsXP problem
I am a newbie to prepared statements and trying to get something simple to
WARNING: Complete newbie to RoR and Ruby alert! * I have a login method
I'm a newbie to Ruby, I have a problem following the Poignant Guide to
Okay, I'm a newbie in C# but I need to create a simple GUI,
(Warning: Clueless Rails Newbie!) In my show.html.erb for my albums view, I call a
Newbie question. I have a NSMutableArray that holds multiple objects (objects that stores Bezier

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.