Change UIActionSheet after doing it's job - iphone

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.

Related

Swift disable touchesEnded

I am trying to disable the TouchesEnded event in my Code when someone clicks on a button. And when the user clicks on another button the TouchesEnded should be activated again.
So for understanding what my app does, every time you click on the screen the text on the screen changes. But when the user clicks the Button a, this touch event should be disabled. And when the user clicks on button b it should be activated again.
i have already tried self.view.isUserInteractionEnabled = false , but then I am not able to click on the button to activate the userInteraction again.
Does anybody as an idea how to fix this problem?
From the behavior you're describing, I'm assuming that your button is a subview of the view that's toggling isUserInteractionEnabled? Setting that flag to false will prevent user interaction on the view's subviews as well. You can fix this by adjusting the view hierarchy so that your button and your self.view are siblings: aka create a container view that has both the button and your referenced self.view as children.
It doesn't make sense to "disable the TouchesEnded event".
You need to enable or disable your buttons and let the events be sent as normal. Alternatively, as you say, you could use isUserInteractionEnabled=false to make a button no longer respond to taps.
Edit:
After rereading your post, I think I understand what you are saying:
"every time you click on the screen the text on the screen changes" - this means clicking anywhere but on the buttons.
"But when the user clicks the Button a, this touch event should be disabled. And when the user clicks on button b it should be activated again."
So you want button clicks to disable/enable taps elsewhere on the screen.
I would suggest using a tap gesture recognizer (UITapGestureRecognizer) attached to the content view for your view controller. Those trigger an action when they fire, and have an isEnabled property. If you set that to false the tap gesture recognizer will stop responding to taps.

Any way to prevent UIActionSheet from being dismissed when user clicks a button in it?

I added a UIProgressView to my UIActionSheet to indicate the download progress. So I do not want my UIActionSheet to be dismissed when user click the download button in it.
But is there a way to do that ?
Right now I implement didDismissWithButtonIndex delegate method to show UIActionSheet again after it was dismissed. But I was hoping there is a better way.
UIActionSheet is a modal view, which means that it blocks UI completely. Since blocking UI is considered a bad practice, preventing an action sheet from dismissing is not supported. Instead, you should make a completely separate progress indicator outside the action sheet.
#Yar, thanks for the answer, I will try your solution some other time.
But I am also satisfied with my current solution. UIActionSheet.h said
// Called when a button is clicked. **The view will be automatically dismissed after this call returns**
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex;
So I guess hit any buttons will always dismiss action sheet. Then my solution is first hide progress bar; when user hits download button, show action sheet again but hide the download button and show progress bar.
The cancel button is always there in case user wants to cancel download even after download is started.

iOS action sheet

I'm using UIActionSheet in one of my applications and I have a question . When the action sheet comes to front , everything else goes in background and I cannot interact anymore with my buttons or other objects in my view until I dismiss the action sheet . Is there a way to disable this feature ? I mean , if I have the action sheet displayed , can I still be able to use what goes in background ? If there is a way , I would really appreciate if you could show me how to do it.
There is no way to access the Background controls, If the UIActionSheet or UIAlertView comes to the front.
The action sheet is supposed to be modal. All user input will be captured by the action sheet until it is dismissed. So all the background controls cannot be interacted with by the user until it is gone.

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];

iPhone app - Show UIActivityIndicator while an IBAction is performed

I want a button in my navbar which lets the user refresh the contents of a tableview. The tableview is already populated and once the user presses the refresh button, I want to show a UIActivityIndicator while I fetch the items to be displayed on the table.
I tried putting a [indicator startAnimating] before calling the method to get the new data of the table (where indicator is of type IBOutlet UIActivityIndicator* and mapped to a control in IB) but the indicator does not show up. Instead, the navbar refresh button is in the pressed position till control returns from this IBAction method.
How can I show the indicator while the method execution completes?
Thanks.
You need to get the new data for the table in the background. That could be an asynchronous network call or a thread depending on what your refresh code does but the UI kind of assumes that button presses are pretty much instantaneous.
You'll note that your whole UI locks up (not just the refresh button), so this is a good thing to do anyway albeit much harder to implement.