UIActivityIndicatorView in a class without a view

Posted by Structurer on Stack Overflow See other posts from Stack Overflow or by Structurer
Published on 2010-06-14T02:12:14Z Indexed on 2010/06/14 2:22 UTC
Read the original article Hit count: 283

Hi

I have defined a class that does a lengthy task and I call it from several other classes. Now I want to show an Activity Indicator while this task is doing it's thing, and then remove it once it's done. Since this is just a boring background task, this class doesn't have a view, and I guess that is where I run into my problem. I can't get this thing to show.

This is what I have done in my class:

    UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 32.0f, 32.0f)];

[activityIndicator setCenter:CGPointMake(160.0f, 208.0f)];
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;

UIView *contentView = [[UIView alloc]initWithFrame:[[UIScreen mainScreen] applicationFrame]];

[contentView addSubview:activityIndicator];
[activityIndicator startAnimating];

// Do the class lengthy task that takes several seconds.....


[contentView release];
[activityIndicator release];

I guess I do something wrong when I get the contentView, but how should I get it properly?

Thanks for any advices...

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about class