2012-01-03 18 views
0

在我的应用程序中,整个视图包含一个webview,它是我的secondViewController。iphone:如何把主页按钮在webView中

现在在我的网络视图中,我打开电子书。

现在我想在我的web视图中放置主页按钮。

我的firstViewController是主页。

有没有什么办法可以从webView到主视图,即firstViewController?

+0

你是怎么首先添加secondViewController?你把它推到navigationController中还是以模态方式呈现? – 0x8badf00d 2012-01-03 12:58:49

+0

PresentModelViewController – Developer 2012-01-03 13:05:43

+1

既然你已经提出了一个模态视图,只需通过[self dismissModalViewControllerAnimated:YES]来解除它; – 0x8badf00d 2012-01-03 14:55:18

回答

4

的链接添加主页按钮,你的HTML代码和封装到一个独特的URL
<a href="GoToHomePage"><img src="HomeButton.png" /></a>

然后实现webView:shouldStartLoadWithRequest:navigationType:委托方法捉点击:

- (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; 
    } 
} 
0

设置FirstviewController HomePage的标题。 然后在FirstviewController从哪里secondviewController被称为

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

然后在secondviewcontroller生成导航控制器和home键也产生去FirstViewController写。

+0

这是什么:** [self.navigationController secondView animated:YES]; **?即使他将secondViewController添加到navigationController以返回到rootViewController,您也可以执行此操作[[self navigationController] popToRootViewControllerAnimated:YES]; – 0x8badf00d 2012-01-03 14:59:06

+0

嗯,回到主页你可以加[[self navigationController] popToRootViewControllerAnimated:YES]; – Rajesh 2012-01-04 05:55:12