Introduction
In this article I will create an Empty View application. Here I will implement a Network Indicator on a Web View in an iPhone. To do that we write code in appdelegate.m for the Objective-C class.
To understand it we use the following.
Step 1
Open XCode by double-clicking on it.
Step 2
Create a New XCode Project by clicking on it.
Step 3
Now Select Empty View Application and click on Next.
Step 4
Now provide your Product Name and Company Identifier.
Step 5
Select the location where you want to save your project and click on Create.
Step 6
Now here we write the code.
AppDelegate.h
#import <UIKit/UIKit.h>
@interface testviewAppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
AppDelegate.m
#import "testviewAppDelegate.h"
@implementation testviewAppDelegate
- (void)dealloc
{
[_window release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
UIWebView *webview =[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
NSString *urladdress =@"http://www.google.com";
NSURL *url = [NSURL URLWithString:urladdress];
NSURLRequest *urlrequest =[NSURLRequest requestWithURL:url];
[webview loadRequest:urlrequest];
[self.window addSubview:webview];
UIApplication *app = [UIApplication sharedApplication];
app.networkActivityIndicatorVisible = YES;
[self.window makeKeyAndVisible];
return YES;
}
@end
Step 7
Finally we click on the run button to show the output.
Step 8
Output in iPhone:
Output 1 in iPhone:
Output 2 in iPhone:
Output 3 in iPhone:
Output 4 in iPhone: