How can we disable the button in my iphone application?

My application has one button in the navigation bar. I want it to work for only 1 user click. If he continuously clicks on it 2 or 3 times immediately after the first click, the button should not receive the next. How can i do this?

My app always crashes if the user taps it more than once. I don't want to make it multithreaded and use blocking. This is why I want to know if there is another alternative.

+2


a source to share


3 answers


(If the app crashes by clicking more than once, it's a big problem.)

Since the button is on the navigation bar, it is a UIBarButtonItem, not a UIButton. UIBarButtonItem has a enabled

property
that you can set to NO to disable the button.



(If it really is a UIButton, don't worry, it also has a enabled

property
.)

+2


a source


After the user clicks the button, you can set the "on" property to "NO", and after the action completes, set it to "YES"



http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIControl_Class/Reference/Reference.html#//apple_ref/occ/instp/UIControl/enabled

0


a source


Fortunately, this is fairly easy to do. The UIBarItem class has an enabled property. Just set it to NO after the user hits it.

0


a source







All Articles