簡體   English   中英

單擊按鈕時打開Webview

[英]Open webview when button is clicked

我創建了一個按鈕,該按鈕通常應打開一個Webview控制器。 但是,當我將代碼連接到按鈕時,它似乎沒有任何作用。

這是我的代碼:

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];
}

我做錯什么了嗎?

請按照以下步驟操作:-

1)像這樣在您的.h文件中添加UIWebViewDelegate

@interface ViewController : UIViewController< UIWebViewDelegate > {

2)現在實現下面的委托方法,它將顯示您的網頁正在加載。

- (void)webViewDidStartLoad:(UIWebView *)webView {     
   NSLog(@"page is loading");       
 }

-(void)webViewDidFinishLoad:(UIWebView *)webView {
       NSLog(@"finished loading");
 }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM