Cocoa: return button status

Discussion in 'Mac Programming' started by wesg, Dec 7, 2008.

  1. wesg macrumors regular

    wesg

    Joined:
    Jan 2, 2008
    Location:
    Toronto, ON
    #1
    I'm adding a push button to my app to trigger the cancel function, but to do that I need to know if a button has been pushed or not.

    Is there a method I can use to query the position of the button? Something like [cancelButton getButtonStatus]; or something. It is an ON/OFF button, which means I'd like to reset the button after it's clicked.

    Any suggestions?
     
  2. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    A button normally doesn't "stay down". Normally something with on/off state is a checkbox. In your controller you could, in your action related to a button, set a member variable indicating that a button has been pressed. Again, a button shouldn't "stay down", and I would imagine you can get the status of a checkbox (but I'm not an expert).

    -Lee
     
  3. wesg thread starter macrumors regular

    wesg

    Joined:
    Jan 2, 2008
    Location:
    Toronto, ON
    #3
    Basically the thing I'm trying to accomplish is have a Cancel button that breaks up my loop. The only I can think of that is to have a conditional statement inside the loop, which currently works. I want to check the status of the button, then cancel accordingly. Unfortunately I just can't figure out how to put it together...
     
  4. Sayer macrumors 6502a

    Sayer

    Joined:
    Jan 4, 2002
    Location:
    Austin, TX
    #4
    Each pass through the loop check a global or call a method like "isCanceled" and have a button call a method to set "isCanceled" to true.

    When the loop comes back around it will check and if "isCanceled" is true, break out of the loop and do any cleanup.

    It's the Occam's razor approach.
     
  5. eviltobz macrumors member

    Joined:
    Nov 12, 2007
    #5
    aye. and you can set something like "alt title" on the button which allows it to change the title when it's clicked, giving it a toggle feel so "start" could change to "stop" or "pause" each click.
     
  6. wesg thread starter macrumors regular

    wesg

    Joined:
    Jan 2, 2008
    Location:
    Toronto, ON
    #6
    I've decided to move onto modal sessions and see where that goes. Can anyone recommend any good tutorials for modal loops and sessions?
     
  7. BravoBug macrumors newbie

    Joined:
    Dec 8, 2008
    Location:
    Oregon, USA
    #7
    It sounds like you're performing some kind of work inside a function/method and you need to have your app respond to a Cancel button click, yes? If that's the case you probably want to move your worker method into its own thread using NSThread. Apple has very good docs on doing this.
     

Share This Page