I have created a button which should normally open a webview controller. However, it doesn't seem to do anything when I connect the code to the button.
Here is my code:
ViewController.h:
@interface ViewController : UIViewController {
IBOutlet UIButton *webscanner;
}
-(IBAction)webscanner:(id)sender;
@property (nonatomic,strong) IBOutlet UIWebView *webView;
ViewController.m:
@synthesize webView;
-(IBAction)webscanner:(id)sender
{
NSString *urlString = @"http://example.com/reader.html";
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlString];
//URL Request Object
NSURLRequest *webRequest = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webView loadRequest:webRequest];
}
Am I doing anything wrong?
Follow the below steps:-
1)Add UIWebViewDelegate
in your .h file like that
@interface ViewController : UIViewController< UIWebViewDelegate > {
2)Now implement the below delegate method which will show your web page is loading.
- (void)webViewDidStartLoad:(UIWebView *)webView {
NSLog(@"page is loading");
}
-(void)webViewDidFinishLoad:(UIWebView *)webView {
NSLog(@"finished loading");
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.