iOS button to webpage with uiwebview

2020-07-27 03:21发布

For a current project I am embedding a mobile site into an iOS app. I've taken use of the goback() and goforward() functions, with UIWebView. But how would I make a custom function that onClick (or onTouch which ever is the correct term) Sends the UIWebView back to the page initially loaded? Any Help would be much appreciated as I have bene unable to find anything on the web thus far.

1条回答
时光不老,我们不散
2楼-- · 2020-07-27 03:28

Add something like to the implementation file:

- (IBAction)loadPage:(id)sender;
{
NSURL *url = [NSURL URLWithString:@"http://www.stackoverflow.com/"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
}

And add this to the header file (each line at the appropriate position):

- (IBAction)loadPage:(id)sender;
IBOutlet UIWebView *webView;

Then bind the button to loadPage within interface builder,
and bind webView to the UIWebView.

Response to comment:

I created this sample project, hopefully it helps:
- http://dd5.org/static/iPhone_Browser_Sample.zip

Binding the button:

Right-click and drag to the class where you added the code above.
Release the button. Now a little dark-gray panel should appear.
Then click on the loadPage: entry within that panel.
If the code was added correctly, the entry should show up there.

查看更多
登录 后发表回答