There are no active ads.

Advertisement

Introduction to iOS Development: Activity Indicator

How do you develop apps for iOS? It’s a common question that many computer enthusiasts ask, and one we here at TechnoBuffalo hope to answer with this series of posts.

Learning how to develop software can be one of the most intimidating prospects for the average computer user, and with the growing saturation of applications in mobile marketplaces, it is becoming increasingly difficult to get your work noticed. That’s what this series is for, helping you learn iOS development from a conceptual perspective. No prior knowledge of computer programming will be necessary. Over the coming weeks, we’ll examine the iPhone’s ability to deliver immersive, intuitive content, a unique opportunity for both developers and consumers.

Today, we’ll be adding an activity indicator to a web browser. This activity indicator will tell users that data is being transmitted and that a webpage is currently being downloaded.

1. First, we must open up Xcode 4, Apple’s latest Integrated Development Environment. Select New Project and follow the on-screen prompts until you are met with the template page. Select View-based Application and make sure that you are targeting the iPhone.

2. After following Xcode’s instructions on setting up the application, entitle the program ActivityIndicator and save the file in a convenient place, preferably one that can be easily remembered and accessed in the future.

3.  First, head over to your initialization file for your view controller (ActivityIndicatorViewController.h). This is where we declare variables that will be defined in our implementation file. We’ll begin by simply creating two IBOutlets, one NSTimer, and one “void” declaration.

——————————————————–

#import <UIKit/UIKit.h>

@interface ActivityIndicatorViewController : UIViewController {

IBOutlet UIWebView *webSite;

IBOutlet UIActivityIndicatorView *activity;

NSTimer *timer;

} 

-(void)timerLoad; 

@end

——————————————————–

4.  Copy the void statement from the last bit of code in the initialization file. Move on over to the implementation file (ActivityIndicatorViewController.m). We’re going to further clarify its properties my adding the code below. We’re also going to uncomment the viewDidLoad method and add some information.

– (void)viewDidLoad

{

[super viewDidLoad];

[webSite loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@”https://www.technobuffalo.com/”]]];

timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0) target:self selector:(timerLoad) userInfo:nil repeats:YES];

——————————————————–

}

-(void)timerLoad{

if (!webSite.loading) {

[activity stopAnimating];

}

else {

[activity startAnimating];

}

}

——————————————————–

5.  Now it’s time to head on over to your interface file, ActivityIndicatorViewController.xib. Drag a Web View into the pane. Double-click on File’s Owner and move to the Connections pane. Here, connect our “technobuffalo” variable with the Web View. Feel free to build and go at this point to ensure that you succeeded in properly connecting our code with the interface element.

6.  Add a Navigation Bar to the program. Then, drag over an Activity Indicator as well. Double-click on File’s Owner, head on over to the connections pane, and then drag the connections to the appropriate elements.

7.  Finally, we can build and run the working application. If you want to make the activity indicator hide after the webpage is finished loading, go to the object’s attributes in the interface file and check the appropriate box. Otherwise, you’re application is finished and should function properly.

Questions?

If you have any questions about the topics discussed in this lesson, feel free to voice them in the comments below. We will do our best to ensure that you have a relatively painless experience developing for iOS. Stay tuned for the next installment of this series, which is released weekly.

To read previous installments from this series, check the links below.

 

 


Jack McGrath

Rooted in his childhood obsession with dismantling and reassembling gizmos and gadgets around the house, Jack McGrath's knowledge of programming,...

Advertisement