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

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.

Related

UINavigation bar reload/refresh button code

I know that at the end my question me sound silly and easy to solve but I have been trying for hours to make it work but it does not work at all.
I have a UINavigation bar with a "back" and a "refresh" button. The back button works perfectly but I haven't found any way to make the refresh button to work.
What I want from the refresh button is to load the whole view again. Like refreshing the whole "viewWillAppear" section.
I have tried view reload and setNeedsDisplay but none of the work.
Is there any way that I can do this?
Can anyone please help me?
Thanks a lot
Move all functions called in viewWillAppear: into a seperate function with appropriate name and call them when someone clicks the refresh button and in the viewWillAppear:. Example
-(void) gpsRedirect{
//Do stuff that you did in viewWillAppear:
}
And use this code for creating a selector that's activated for touch up inside event upon a button. This will trigger the method gpsRedirect which contains what you previously did in viewWillAppear:
[barButtonItemName addTarget:self
action:#selector(gpsRedirect)
forControlEvents:UIControlEventTouchUpInside];

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.

How to take control of Dismissal of UIAlertView in iPhone

I need to know if I can decide in the action method of the Buttons of UIAlertView whether to dismiss the alertView or not. In short On click of certain buttons of AlertView, I dont want my alert view to dismiss.
There's no way that I know of to do this. But it sounds like you're using UIAlertView in a manner for which it's not really intended. What are you actually trying to accomplish?
I ended up adding my own custom button instead of using the ones provided by the AlertView. After assigning my own actions to this Buttons I was able to control the dismissal of the alertview from those actions.

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.

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.