Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

wesg

macrumors regular
Original poster
Jan 2, 2008
211
0
Toronto, ON
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?
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
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
 

wesg

macrumors regular
Original poster
Jan 2, 2008
211
0
Toronto, ON
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...
 

Sayer

macrumors 6502a
Jan 4, 2002
981
0
Austin, TX
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.
 

eviltobz

macrumors member
Nov 12, 2007
76
0
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.
 

wesg

macrumors regular
Original poster
Jan 2, 2008
211
0
Toronto, ON
I've decided to move onto modal sessions and see where that goes. Can anyone recommend any good tutorials for modal loops and sessions?
 

BravoBug

macrumors newbie
Dec 8, 2008
26
0
Oregon, USA
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?

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.