如何使用UIButton使UIWebView返回

时间:2015-04-16 00:17:28

标签: ios uiwebview

我有一个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
    }

1 个答案:

答案 0 :(得分:1)

这样的事情应该让你去

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