开发者

How to show some processing while some background task is going on?

开发者 https://www.devze.com 2023-01-27 01:54 出处:网络
I am making an iPhone app wherein I need users to enter their email ID and password, and then they can access their account on my website.

I am making an iPhone app wherein I need users to enter their email ID and password, and then they can access their account on my website.

Once they ente开发者_运维问答r the authentication details they must wait for a few seconds for the next page to come up.

I need to show a "Processing" or "Please Wait" kind of symbol to the user.

How should I implement it?

Help me, please.


What you are searching for is an activity indicator.

Here is the tutorial for the activity indicator.

http://www.edumobile.org/iphone/iphone-programming-tutorials/use-activityindicator-in-iphone/

Hope it helps you


I usually create a UIView that gets instantiated as needed. Here's some code for you to try in your own app:

- (id)initWithLabel:(NSString*)labelName {
    self = [super init];
    if (self) {
        UIImageView *loadingBackgroundView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 150, 120, 40)];
        [loadingBackgroundView setBackgroundColor:[UIColor blackColor]];
        [loadingBackgroundView setAlpha:0.9];
        [loadingBackgroundView.layer setCornerRadius:8.0];
        [loadingBackgroundView.layer setBorderColor:[[UIColor clearColor] CGColor]];
        [self addSubview:loadingBackgroundView];
        [loadingBackgroundView release];

        UILabel *loadingLabel = [[UILabel alloc] initWithFrame:CGRectMake (125, 160, 100, 20)];
        [loadingLabel setBackgroundColor:[UIColor clearColor]];
        [loadingLabel setTextAlignment:UITextAlignmentCenter];
        [loadingLabel setTextColor:[UIColor whiteColor]];
        [loadingLabel setText:labelName];
        [self addSubview:loadingLabel];
        [loadingLabel release];

        UIActivityIndicatorView *loadingActivityIndicatorView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(110,160,20,20)];
        [loadingActivityIndicatorView setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhiteLarge];
        [loadingActivityIndicatorView startAnimating];
        [self addSubview:loadingActivityIndicatorView];     
        [loadingActivityIndicatorView release];
    }
    return self;
}

This will give you something similar to the below:

How to show some processing while some background task is going on?


As ParthBhatt noted it's an activity indicator you want.

I quite like David Sinclair's DSActivityView class: extremely easy to implement, easy to show and change messages, it can be used to disabled the UI by covering it, including a tab bar and nav bar, if desired.

http://www.dejal.com/developer/dsactivityview


This is something that has been handled by lots of people, so if you want to take advantage of someone else's work and avoid reinventing the wheel, you could use something like the Tapku Library. It's open source and on GitHub.

Specifically, check out the TKProgressAlertView and TKLoadingView classes.

0

精彩评论

暂无评论...
验证码 换一张
取 消