【问题标题】:Problem with UIWebViewUIWebView 的问题
【发布时间】:2010-09-02 20:41:06
【问题描述】:

当我单击 UIWebView 中的超链接时,我正在尝试启动外部 safari,但在我的情况下没有任何反应。如果我尝试将目标包含为空白并跳过 UIWebView 委托方法,它会在同一视图中启动 safari..请指导我的朋友如何在点击 UIWebView 中的链接时打开外部浏览器..这是我的代码..I正在以编程方式创建 UIWebView

CGRect webFrame = CGRectMake(10,78,300,50);  
         contactUsView.delegate = self;
         contactUsView = [[UIWebView alloc] initWithFrame:webFrame];  
         [contactUsView setOpaque:NO];
         contactUsView.backgroundColor = [UIColor clearColor];  
        NSString *html = @"<html><head></head><body>Copyright \u00A9 2010 <a href='http://www.example.com'>Hello</a><br/>Hi  <a href='http://example1.com>Click here</a></body></html>";  
         [contactUsView loadHTMLString:html baseURL:[NSURL URLWithString:@"http://www.solstice-consulting.com"]]; 



- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request  
 navigationType:(UIWebViewNavigationType)navigationType; {  

    NSURL *requestURL = [ [ request URL ] retain ];  
    NSLog(@"expected:%d, got:%d", UIWebViewNavigationTypeLinkClicked, navigationType);

    if ( ( [ [ requestURL scheme ] isEqualToString: @"http" ]  
          || [ [ requestURL scheme ] isEqualToString: @"https" ] )  
        && (navigationType == UIWebViewNavigationTypeLinkClicked ) ) {  
        return ![ [ UIApplication sharedApplication ] openURL: [ requestURL autorelease ] ];  
    }  

    [ requestURL release ];  

    return YES;  
}  

日志输出预期为 0,得到为 5..我不明白该怎么做..

【问题讨论】:

  • [request URL] 上的retain 仍然存在内存泄漏。 retain 不是必需的。摆脱它。

标签: iphone html objective-c uitableview uiwebview


【解决方案1】:
NSURL *requestURL = [request URL]; 
NSString* urlString = [requestURL absoluteString];
if ([urlString isEqualToString: @"http://www.example.com"])
{

   // Try this, it will work fine

}

【讨论】:

    【解决方案2】:

    改变你的
    (navigationType == UIWebViewNavigationTypeLinkClicked)

    (navigationType == UIWebViewNavigationTypeLinkClicked || navigationType == UIWebViewNavigationTypeOther)

    【讨论】:

      猜你喜欢
      • 2011-08-13
      • 2016-01-18
      • 2011-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-03
      相关资源
      最近更新 更多