UIActivityIndicatorView UIActionSheet modal loading screen

How do I show a loading screen?  A modal loading indicator.

So you need to do a web request and wait for a response, you don’t want the user to interfere while this is happening?  Welcome UIActionSheet and UIActivityIndicatorView.

So I send a multi-form http post request, and need to wait for a response.

Just before it sends I do the following

Note that I am inside a UIView UIScrollView UITabBarController

UIActivityIndicatorView *progressView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(12.4, 18, 25, 25)];
progressView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
progressView.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleBottomMargin);

UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:@"Uploading Company Info"
delegate:self
cancelButtonTitle:@"Stop"
destructiveButtonTitle:nil
otherButtonTitles:nil];

[menu addSubview:progressView];
[menu showInView:self.view];
[menu setBounds:CGRectMake(0,0,320, 175)];

[progressView startAnimating];

then do your code that will take some time..

once it is complete

[menu dismissWithClickedButtonIndex:0 animated:YES];

I suggest doing whatever it is that takes a while (blocking web request) on another thread.  I will go over how to do this on another post (Once I have it worked out, haha..)

Also, note I am in a UIViewController

<UIPickerViewDelegate, UIPickerViewDataSource, UIActionSheetDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate>

controller.  As it stands I haven’t shown you how to respond to the clicking of the ‘Stop‘ button.  It will make the loading screen disappear by default.

Using the

delegate:self

will send that button click back to your controller on

– (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{}

and you can do as you please with it.

This is just a snippet to get you started.  The numbers I have used above for dimension’s were worked out with trial and error.  I primarily use the Interface Builder for my UI stuff so I’m yet to get my head around properly placing UI objects in views.

Posted on March 3, 2009 at 9:04 am by Jordan Carter · Permalink
In: Iphone · Tagged with: , ,

One Response

Subscribe to comments via RSS

  1. Written by Jeyremy
    on August 28, 2012 at 8:42 pm
    Permalink

    Thanks a lot ! it’s exactly what i was looking for, you save my day !

Subscribe to comments via RSS

Leave a Reply