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.
Asked
Active
Viewed 3,541 times
1 Answers
4
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.

Anne
- 26,765
- 9
- 65
- 71
-
Thank you! This makes much more sense now. I do have one question though, When I go into the interface builder loadPage does not show up as a option. I'm really new to iOS development so this is all a bit confusing. Do I need to put the ID of the button in the code or does the button send the function the ID? – rajh2504 Mar 02 '11 at 20:52
-
I added some additional info to the original answer, check the sample project. – Anne Mar 02 '11 at 22:33
-
Can you please re-post the project? I get a 404 error on that page. – Klinetel Jan 10 '13 at 05:36
-
Oops, the static folder was moved during server transition. Fixed `:)` – Anne Jan 10 '13 at 20:04