簡體   English   中英

如何使用UIButton使UIWebView返回

[英]How to use UIButton to make UIWebView go back

我有一個UIWebView,我想當用戶轉到其中的鏈接時可以返回此處,這是我的Webview代碼

    UIWebView *webView = [[UIWebView alloc]  initWithFrame:CGRectMake(0, 0, 320, 430)];   // x is width,y is hght


    NSString *urlAddress = @"http://livewiretech.co.nf/   NSURL *url =  [NSURL URLWithString:urlAddress];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [webView loadRequest:request];
    [self.view addSubview:webView];

我有一個UIButton,它的代碼是

    -(void) backButtonPressed {
    //Back code here
    }

這樣的事情應該讓你走

@property (nonatomic, strong) UIWebView * webView;

....

webView = [[UIWebView alloc]  initWithFrame:CGRectMake(0, 0, 320, 430)];   // x is width,y is hght

NSString *urlAddress = @"http://livewiretech.co.nf/";
NSURL *url =  [NSURL URLWithString:urlAddress];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
[self.view addSubview:webView];


 -(void) backButtonPressed {
    if ([webView canGoBack]) {
        [webView goBack];
    }
 }

暫無
暫無

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

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