UIWebView to display web content (Cocoa Framework)

UIWebViews can be used to display web pages (for example, within iPhone applications). The snippets below demonstrate a view controller to display http://snipd.net .

Header file

//
//  ExampleViewController.h
//
//  Created by Ferhat Yildiz on 7/12/11.
//

#import <UIKit/UIKit.h>

@interface ExampleViewController : UIViewController<UIWebViewDelegate> {
	IBOutlet UIWebView *webView;
}

@property (nonatomic, retain) IBOutlet UIWebView *webView;

- (void)loadLink:(NSString*)link;

@end

View controller

//
//  ExampleViewController.m
//
//  Created by Ferhat Yildiz on 7/12/11.
//

#import "ExampleViewController.h"

@implementation ExampleViewController

@synthesize webView;

- (void)viewDidLoad {
    [super viewDidLoad];
	[self loadLink:@"http://snipd.net"];
}

- (void)loadLink:(NSString*)link {
	NSLog(@"Opening: %@",link);
	NSString *urlAddress = link;
	NSURL *url = [NSURL URLWithString:urlAddress];
	NSURLRequest *request = [NSURLRequest requestWithURL:url];
	[webView loadRequest:request];
}

- (void)webViewDidStartLoad:(UIWebView *)webView {
	[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
	[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)dealloc {
    [super dealloc];
}

@end

The View in Interface Builder

UIWebView

 

 

 

This entry was posted in Objective-C and tagged , , , , , , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Why ask?