I have a time-consuming step to be done, if the user clicks on a certain button on an uialertview. I would like to notify the user with an activity indicator while its being done. Im not sure what exactly needs to be done for the desired output. Here is the flow:
User clicks on button 1 ‘Build the tower’.
UIAlertview shown with “Do you want to do this, it takes time”
User clicks “YES”:
Now I am in the alertview Delegate method.
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 1) {//Yes the user wants to do this
//Show activity indicator here
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50);
[indicator startAnimating];
[alertView addSubview:indicator];
[indicator release];
//
[SimpleFunctions doThatMethodThatTakesALongTime];
//remove activity indicator here
}
}
Here, I want to show an activity indicator before the ‘big processing’ is done.
The examples of adding an activity indicator to alertview show how to add the indicator to the above alertview. But I don’t want that indicator to show up, until the user has clicked on ‘YES’.
Any pointers on how that can be achieved would be great. I hope I made the question clear, please let me know if not,
Thanks
Alert view reference: http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIAlertViewDelegate_Protocol/UIAlertViewDelegate/UIAlertViewDelegate.html
In the delegate method
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndexyou can add things to the alertView there.E.g.
You want to add
aias a ivar (class variable) in order to remove it later.[self.ai removeFromSuperview];Hope this helps.
Edit: one thing to keep in mind is that this way you will probably have to manage dismissing of your alert view yourself. You can use the method
- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animatedon the alert view to dismiss it.