【问题标题】:Question about UIWebview when tapping links点击链接时关于UIWebview的问题
【发布时间】:2011-06-17 18:47:22
【问题描述】:

我有一个加载 html 文件的 UIWebView。一旦用户单击链接,我希望 url 在自定义 UIWebview 中打开。 我尝试了一些东西:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    NSString *htmlPath = [[NSBundle mainBundle] pathForResource:@"MyiPadHTML"
                                                         ofType:@"html"];
    NSURL *url = [NSURL fileURLWithPath:htmlPath];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [webview loadRequest:request];       
}

else  {
    NSString *htmlPath = [[NSBundle mainBundle] pathForResource:@"MyHTML" 
                                                         ofType:@"html"];
    NSURL *url = [NSURL fileURLWithPath:htmlPath];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [webview loadRequest:request];   
}

这是我,根据设备加载文件。这很好用。我在- (void)viewDidLoad方法中做到了

【问题讨论】:

  • 您的意思是您希望它加载到不同的UIWebView 对象中?
  • 是的。在不同的自定义 UIWebview 中。

标签: ios xcode cocoa-touch uiwebview


【解决方案1】:

这不应该工作吗?

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    if ( navigationType == UIWebViewNavigationTypeLinkClicked ) {
        [myOtherCustomWebView loadRequest:request];

        return NO;
    }

    return YES;
}

【讨论】:

  • 哦,不,你不是我忘了检查OK。再次感谢您的帮助:)
猜你喜欢
  • 2011-07-11
  • 2014-02-25
  • 2013-07-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-08
  • 1970-01-01
  • 2010-11-19
相关资源
最近更新 更多