iOS button to webpage with uiwebview

回眸只為那壹抹淺笑 提交于 2019-12-09 21:59:31

问题


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:


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.



来源:https://stackoverflow.com/questions/5173053/ios-button-to-webpage-with-uiwebview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!