Peter Warbo
Peter Warbo

Reputation: 11700

iOS - Show UIActivityIndicatorView when table is being loaded

I have a tab bar application. I have 2 questions.

Upvotes: 2

Views: 9653

Answers (2)

Manuel
Manuel

Reputation: 10303

You can use this inside the activity:

protected Dialog onCreateDialog(int id) {
        ProgressDialog progress = new ProgressDialog(this);
        progress.setMessage("The information is gathered, one moment please.");
        progress.setIndeterminate(true);
        progress.setCancelable(false);
        progress.setCanceledOnTouchOutside(false);
        return progress;
}

This will show an alert once you call this in(or on) the activity:

showDialog(0x0001);

When the dialog has to fade out call this:

removeDialog(0x0001);

EDIT

Now for objective-c:

UIAlertView alert = [UIAlertView initWithTitle:@"a title" message:@"a message" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil]
[alert show];

if(alert != nil) {
        UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

        indicator.center = CGPointMake(alert.bounds.size.width/2, alert.bounds.size.height-45);
        [indicator startAnimating];
        [alert addSubview:indicator];
        [indicator release];
}

EDIT Removing it is done with this:

[alert dismissWithClickedButtonIndex:0 animated:YES];
[alert release];

/EDIT

That worked for me:) it could be its not totally spot on becouse i changed some stuff in the browser to now thow company secrets etc xD :). Feel free to ask stuff about it.

Upvotes: 10

EmptyStack
EmptyStack

Reputation: 51374

  1. YES. Even if you don't give any default image, it will load the first view controller showing a black screen.

  2. Display the activity indicator view in your second view controller's loadView. And, put all the loading code in your second view controllers viewDidAppear: method. By doing this, your second view controller will be displayed with the activity indicator view as soon as you press the second tab. And after the loading is completed, dismiss the activity indicator. This will give you a smooth transition from one tab to the other.

Upvotes: 3

Related Questions