loadRequest uiwebview


 

loadRequest uiwebview

The example exhibits the use of loadRequest method in UIWebView.

The example exhibits the use of loadRequest method in UIWebView.

loadRequest uiwebview

The example exhibits the use of loadRequest method in UIWebView.

loadRequest is basically a method that can be used to load any web page over web view in iPhone application. The method can be written as

- (void)loadRequest:(NSURLRequest *)request;

In this example we are loading the home page of Rose India website. Final application will look alike ..

loadRequest example

Create a View based application in xCode and save it. After that define the outlet and property of UIWebView in .h and synthesize it in .m file. Also release it in dealloc method.

for example..

#import <UIKit/UIKit.h>

@interface readDataViewController : UIViewController {
UIWebView* myview;
}
@property(nonatomic, retain)IBOutlet UIWebView* myview;
@end

#import "readDataViewController.h"

@implementation readDataViewController
@synthesize myview;

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

- (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 {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}

@end

Once you done, just open the viewController.xib in Interface builder and drop the UIWebView onto the UIView from the library and connect it with the file owner.

Uncomment the ViewDidLoad method from the implementation file, and paste the given loadRequest method inside it.

- (void)viewDidLoad {
[super viewDidLoad];

[myview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.roseindia.net/"]]];
}

Build the application to test. It will load the requested URL on the Web View.

Download Code

Ads