NSButton

  • Hi,
    I want to disable the NSButton on click of it and enabled it again
    when it finish it work.
    I have written a code for this like follow;
    (IBAction)setDestination:(id)sender
    {
      [sender setEnabled:NO];
      /*
        My function code here
      */
      [sender setEnabled:YES];
    }

    But if i debug this code it's not disabled the button after first
    statement so if i click on the button continuously it hangs the
    application.
  • I would strongly recommend you learn a little about multithreading. In
    your "My function code here" bit, your application is blocking the
    main thread so users can't actually click the button anyway. Instead,
    you need to disable the button and then perform the work on a separate
    thread. Once that has finished you can re-enable the button again.

    Mike.

    On 8 Oct 2007, at 14:01, santosh wrote:

    > Hi,
    > I want to disable the NSButton on click of it and enabled it again
    > when it finish it work.
    > I have written a code for this like follow;
    > (IBAction)setDestination:(id)sender
    > {
    > [sender setEnabled:NO];
    > /*
    > My function code here
    > */
    > [sender setEnabled:YES];
    > }
    >
    > But if i debug this code it's not disabled the button after first
    > statement so if i click on the button continuously it hangs the
    > application.
  • I agree with Mike.. to add to what he has already said, I would look
    at NSThread documentation and before your thread exits, call the
    [ buttonReference setEnabled:YES ].  Providing that you have a
    reference to the button in your code somewhere.

    On Oct 8, 2007, at 12:13 PM, Mike Abdullah wrote:

    > I would strongly recommend you learn a little about multithreading.
    > In your "My function code here" bit, your application is blocking
    > the main thread so users can't actually click the button anyway.
    > Instead, you need to disable the button and then perform the work on
    > a separate thread. Once that has finished you can re-enable the
    > button again.
    >
    > Mike.
    >
    > On 8 Oct 2007, at 14:01, santosh wrote:
    >
    >> Hi,
    >> I want to disable the NSButton on click of it and enabled it again
    >> when it finish it work.
    >> I have written a code for this like follow;
    >> (IBAction)setDestination:(id)sender
    >> {
    >> [sender setEnabled:NO];
    >> /*
    >> My function code here
    >> */
    >> [sender setEnabled:YES];
    >> }
    >>
    >> But if i debug this code it's not disabled the button after first
    >> statement so if i click on the button continuously it hangs the
    >> application.

  • Yes you're right. I stand corrected.

    Cheers,
    Hasani

    On Oct 8, 2007, at 3:30 PM, Emanuele ∞ Vulcano wrote:

    >
    > Il giorno 08/ott/07, alle ore 21:47, Hasani Hunter ha scritto:
    >
    >> I agree with Mike.. to add to what he has already said, I would
    >> look at NSThread documentation and before your thread exits, call
    >> the [ buttonReference setEnabled:YES ].  Providing that you have a
    >> reference to the button in your code somewhere.
    >
    > Note that the advice is good but misleading -- AppKit classes, such
    > as buttons, should not be manipulated by secondary threads. A good
    > way would be to call something with performSelectorOnMainThread:...
    > which in turn does the setEnabled: bit.
    >
    > - ∞
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today