How do I get a UIView to appear instantly?

Posted by matsgrip on Stack Overflow See other posts from Stack Overflow or by matsgrip
Published on 2010-04-14T09:00:08Z Indexed on 2010/04/14 9:03 UTC
Read the original article Hit count: 390

I'm trying to create an activity indicator in iPhone app. The problem is that I cannot get it to appear before the actual task i want it to diplay during is already done. Is there something funky about the order in which the iPhone does stuff?

Here is my problematic code (in my app delegate):

-(BOOL)showProgressView: (NSString *) message { 
self.progress = [[UIView alloc] initWithFrame:window.frame];

UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage    imageNamed:@"squircle.png"]];
[img setAlpha:0.5];
[img setFrame:CGRectMake(94, 173, 133, 133)];


UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(51.5, 51.5, 30, 30)];
spinner.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;

[img addSubview:spinner];

[self.progress addSubview:img];


[spinner startAnimating];
[img release];
[spinner release];

[window addSubview:self.progress];

return YES;

}

I then call this code like this:

if ([appDelegate showProgressView:@"Loading..:"])
{

    //My actual code loads data and stuff here but that is not important
            //drawCtrl is a UIViewController subclass that is instantiated here 


    UINavigationController *navController = [appDelegate navigationController];
    [navController pushViewController:drawCtrl animated:YES];


    [drawCtrl release];
}

The problem is that my activity indicator does not appear until the new view controller is pushed onto the navController's stack. Can I control this in some way?

Thanks in advance!

-Mats

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about iphone