【问题标题】:iphone:how to put Home button in webViewiphone:如何在 webView 中放置主页按钮
【发布时间】:2012-01-03 12:53:14
【问题描述】:

在我的应用中,整个视图包含一个 webview,它是我的 secondViewController。

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

现在我想把主页按钮放在我的网页视图中。

我的 firstViewController 是主页。

有什么方法可以从 webView 转到 home view 即 firstViewController 吗?

【问题讨论】:

  • 你是如何将 secondViewController 添加到 first 的?你是把它推送到 navigationController 还是以模态方式呈现?
  • 既然你已经展示了一个模态视图,只需通过 [self dismissModalViewControllerAnimated:YES]; 将其关闭

标签: iphone ios xcode webview


【解决方案1】:

将主页按钮添加到您的 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;
    }
}

【讨论】:

    【解决方案2】:

    设置 FirstviewController 主页的标题。 然后写在调用 secondviewController 的 FirstviewController 中

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

    然后在 secondviewcontroller 中生成一个导航控制器,并生成一个主页按钮以转到 FirstViewController。

    【讨论】:

    • 这是什么:[self.navigationController secondView animated:YES]; ?即使他将 secondViewController 添加到 navigationController 以返回 rootViewController 你也会这样做 [[self navigationController] popToRootViewControllerAnimated:YES];
    • 是的,要返回首页,您可以添加 [[self navigationController]popToRootViewControllerAnimated: YES];
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-01
    • 1970-01-01
    • 2011-10-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-04
    相关资源
    最近更新 更多