How to add webview in iphone?

Leave a Comment
This is a complete example demo of webview in iphone programming. I am giving complete steps to use web view in your example.Let's start

Step 1:   Create Webview single view application.


Step 2: Now from object library drag webview in your iphone viewcontroller xib file.



Step 3: Now create outlet by dragging webview to viewcontrooler.h file.
@property (weak, nonatomic) IBOutlet UIWebView *webview;


 Step 4: After creating outlet viewcontroller.h file look like.

Step 5: Now run your simulator. result is nothing. because we have to give delegate of it


Step 6: select webview and connect it with file's responder and give delegate.


 Step7: Give url to webview like this.

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.studyoverflow.org/"]];
    [webview loadRequest:request];

Step 8: Now run your application and achieve your target...


devangViewController.h
#import <UIKit/UIKit.h>
@interface devangViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIWebView *webview;
@end


devangViewController.m
#import "devangViewController.h"
@interface devangViewController ()
@end
@implementation devangViewController
@synthesize webview;
- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.studyoverflow.org/"]];
    [webview loadRequest:request];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end



I hope you will be clear after this tutorial..If you have any doubts than leave comment or mail me on devang9978@gmail.com ..

Devang Patel
(Iphone Developer by www.techstudy.net)

0 comments:

Post a Comment