Developer
Developer

Reputation: 1435

iphone:how to put Home button in webView

In my app the whole view contains a webview which is my secondViewController.

Now in my web view i open the eBook.

Now i want to put home button in my webview.

My firstViewController is the home page.

Is there any way to go from webView to home view ie firstViewController?

Upvotes: 0

Views: 1272

Answers (2)

Matt Garrod
Matt Garrod

Reputation: 878

Add the home button to your HTML code and enclose it in a link to a unique URL
<a href="GoToHomePage"><img src="HomeButton.png" /></a>

Then implement the webView:shouldStartLoadWithRequest:navigationType: delegate method to catch the click:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
    if (navigationType == UIWebViewNavigationTypeLinkClicked && [[[request URL] absoluteString] isEqualToString:@"GoToHomePage"]) {
        [self.presentingViewController dismissModalViewControllerAnimated:YES];
        return NO;
    } else {
        return YES;
    }
}

Upvotes: 4

Rajesh
Rajesh

Reputation: 784

Set title of the FirstviewController HomePage. then write in the FirstviewController from where the secondviewController is called

SecondViewController *secondView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
[self.navigationController secondView animated:YES];  
[secondView release];

then in the secondviewcontroller a navigation controller is generated and a home button is also generated to go FirstViewController.

Upvotes: 0

Related Questions