Use ActivityIndicator in iPhone

The iPhone SDK provides the UIActivityIndicatorView to tell a user to “Please wait,I’m processing”. The UIActivityIndicatorView uses a spinning “gear” to tell a user an application is processing and that it will eventually complete.

The iPhone SDK provides the UIActivityIndicatorView to tell a user to “Please wait,I’m processing”. The UIActivityIndicatorView uses a spinning “gear” to tell a user an application is processing and that it will eventually complete.

Step 1: Create a View-base application using template. Give the name of the application ActivityIndicator.

Step 2:  Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: Expand classes and notice Interface Builder created the ActivityIndicatorViewController class for you. Expand Resources and notice the template generated a separate nib, ActivityIndicatorViewController.xib for the ActivityIndicatorViewController.

Step 4: Open ActivityIndicatorViewController , add an IBOutlet for a UIActivityIndicatorView, and add an IBAction called PressMe. Make the following changes in the ActivityIndicatorViewController.h file.

#import <UIKit/UIKit.h>
@interface ActivityIndicatorViewController : UIViewController {
IBOutlet UIActivityIndicatorView * activityView;
}
@property(nonatomic,retain)  UIActivityIndicatorView * activityView;
-(IBAction) pressMe:(id) sender;

Step 5: Double click your ActivityIndicatorViewController.xib file and open it to the Interface Builder. First,drag Round Rect button from the library and place it to the view window. Double click it and give the name PressMe. Now single click it and drag from the Touch Up Inside to the File’s Owner icon select PressMe: action. Drag activity indicator view from the library and place it to the view window. Connect File’s Owner to the activity indicator and select activityView. Save your .xib file and go back to the Xcode.

Step 6: Now make the following changes in the ActivityIndicatorViewController.m file.

@synthesize activityView;
-(IBAction) pressMe:(id) sender
{
if([activityView isAnimating])
[activityView stopAnimating];
else
[activityView startAnimating];
}

Step 7:  Compile and run the application in the simulator.

You can downloaded SourceCode from here ActivityIndicator 2

WP Greet Box icon
Hello there! If you are new here, you might want to subscribe to the RSS feed for updates on this topic, and free programming tips and tricks and source code            snippets.

Leave a Reply

Security Code:

learn iphone programming

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Our Mobile Training Courses

EDUmobile.ORG offers the following 4 Mobile Training Courses. Our iPhone Training Course is very popular, with over 200 developers in training.

learn iphone programming
© 2010 EDUmobile.ORG