How can we disable the button in my iphone app? - iphone

In my application, there is one button in the navigation bar. I want it to work only for the 1t click of the user. If he continousally presses on it 2 or 3 times just after the 1st click the button shouldnt recieve the following ones. How can I do this?
My app always crashes if the user presses it for more than once. I dont want to make it multithread and use lock. Thats why i want to know whether there is anyother alternative.

(If the app crashes by pressing more than once then there's a bigger problem.)
Since the button is on the navigation bar, that's a UIBarButtonItem, not a UIButton. The UIBarButtonItem has an enabled property which you can set to NO to disable the button.
(If it is really a UIButton, don't worry, it also has an enabled property.)

After the user clicked the button, you could set the "enabled" property to NO and after the action finished, set it back to YES
http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIControl_Class/Reference/Reference.html#//apple_ref/occ/instp/UIControl/enabled

Luckily this is pretty easy to do. The UIBarItem class has an enabled property. Just set it to NO once the user taps it.

Related

UINavigationButton & UIButton on PopToRootViewController?

My app has a sign in button and a sign up button, which are UINavigationButtons and UIButtons respectively. Either segues to a new screen that, on success, should PopToRootViewController; However, when I successfully sign in, my sign in and sign up buttons are still present. I have a method that decides whether or not to display the buttons that gets called in the viewDidLoad method. Thus, when I stop/run the app again, the buttons disappear as they should. Can anyone give me advise on how to get these buttons to hide? Thank you.
Bonus points: I also have a log out button that has a similar issue; I have to re-run the app before my view controller realizes it should hide the logout button and show the sign in/up buttons.
The problem is that viewDidLoad is only called once, so it is hardly suitable for this purpose; it has to do with the view coming into existence, and nothing to do with the interface. Use viewWillAppear: and make the decision about whether to show or hide the buttons on the basis of, say some info you've stored in NSUserDefaults (like, has the user signed in or not).

What is the view or thing called that pops up in the photos app when you click the leftmost button at the bottom of the screen on the iPhone?

I want to implement this on my app. I want to search for tutorials on this topic but I don't know what its called. Can someone please tell me what its called? Eg. In the photos app in iPhone, when u click on the left most button at the bottom, a screen pops up from the bottom giving you options to either email image, set as wallpaper etc.. So, once again, what is this called? Thanks
That is a UIActionSheet. Check out the UIActionSheet Class Reference.
Basically you create one with the designated initializer -initWithTitle:delegate:cancelButtonTitle:destructiveButtonTitle:otherButtonTitles: then send the -showInView: message to display it. You'll have to set yourself as it's delegate in order to handle selections made by the user.
The button is the 'action' barButtonItem type.
The button then opens a modal sheet. Opened with something like:
[self presentModalViewController:menuViewController animated:YES];

UINavigationController Back Button position

Ist it possible to set the back button of UINavigationController to the right side programatically?
You could create a custom button and place in on the right hand side. You could assign an action to the button which performs your going back functionality.
The problem with this is that your back button wouldn't have the look and feel of the traditional back button that users have come to expect, and your app may be rejected for going against this very common user interface design.

Change UIActionSheet after doing it's job

I have to import some XML data into my app.
Now I open a UIActionSheet and add as a subview a UIActivityIndicatorView. Initially I show a progress wheel and a button with 'Cancel'.
When the XML has been imported, I want to hide the progress wheel (this it's easy) and change the button into a 'Done' button, all in the same UIActionSheet.
What I'm doing now is closing the UIActionSheet with the option dismissWithClickedButtonIndex, but I don't like this way because it's the same as pressing 'Cancel', and then I show an UIAlertView displaying "All data has been imported".
Is this possible ?
You shouldn't be doing that, when it loads correctly just dismiss the ActionSheet. On the other hand if an error occurs then display an alert.
Think about the user who will use the app multiple times a day, a Done message each time will be a waste of time.
UPDATE
As i understand your goal is to use the ActionSheet just as a popup (with Cancel ability), if so, just call dismissWithClickedButtonIndex:animated: when your XML loading is done.
If its successful then just call the dismiss method, if its unsuccessful then call the dismiss and popup an alert
This is a bit of a hack but should work. Note that there is a good chance that this will result in your app not being accepted into the app store as you're messing around with the action sheet in ways Apple didn't intend.
Initially display the action sheet with both the 'Done' and 'Cancel' buttons. Before displaying the sheet hide the 'Done' button using its hidden property. To see how to access the 'Done' button see this question.
Then when you're hiding the UIActivityIndicatorView, also change the hidden property of both the 'Cancel' and 'Done' buttons, so that the 'Done' button becomes visible. If the 'Done' button appears in the wrong position move it by modifying its centre property.

Button works in simulator for not in App

I have a few different views in my App, all of which are viewed by tapping different buttons. All the buttons work on the simulator, but when I run the app on the device only one button does not work. I went over and over my code and re coded that one button and re-connected it in IB to make sure that i did not mess something dumb up, but it still freezes my app.
When the bad button is tapped the App will freeze but not shut off and the only way to unfreeze it is to press the home button.
Any thoughts on why this might be happing only to this one button?
I got it! It was something really dumb! In the view that is loaded when the button is tapped there is a picker. What was happening is that I have a BOOL value that needs to be set to true when the button is tapped and I forgot to set it. Without that BOOL value being set the picker was not being loaded the right way.