[英]Open webview when button is clicked
I have created a button which should normally open a webview controller. 我创建了一个按钮,该按钮通常应打开一个Webview控制器。 However, it doesn't seem to do anything when I connect the code to the button.
但是,当我将代码连接到按钮时,它似乎没有任何作用。
Here is my code: 这是我的代码:
ViewController.h: ViewController.h:
@interface ViewController : UIViewController {
IBOutlet UIButton *webscanner;
}
-(IBAction)webscanner:(id)sender;
@property (nonatomic,strong) IBOutlet UIWebView *webView;
ViewController.m: 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 1)像这样在您的.h文件中添加
UIWebViewDelegate
@interface ViewController : UIViewController< UIWebViewDelegate > {
2)Now implement the below delegate method which will show your web page is loading. 2)现在实现下面的委托方法,它将显示您的网页正在加载。
- (void)webViewDidStartLoad:(UIWebView *)webView {
NSLog(@"page is loading");
}
-(void)webViewDidFinishLoad:(UIWebView *)webView {
NSLog(@"finished loading");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.