在我的應用程序中,我使用的UIWebView,我需要一些超鏈接電話號碼,電子郵件& URLs.I做了以下內容:iPhone:在Safari中的UIWebView開放的超級鏈接
- (void)viewDidLoad
{
credits.delegate=self;
}
-(void)loadScreen
{
scroll=[[UIScrollView alloc]init];
credits=[[UIWebView alloc]init];
NSString *Address = @"www.***.com/php/getjson.php?method=";
jmax = [NSURL URLWithString:Address];
NSData *Data =[ NSData dataWithContentsOfURL:jmax];
String = [[NSString alloc] initWithData:Data encoding:NSUTF8StringEncoding];
NSString * creditsHtml = [NSString stringWithFormat:@" <font face=\"Arial\"><H3 align=\"center\"> Credits </H3> %@ <br>Phone%@</font>", String,phone];
credits.userInteractionEnabled = YES;
credits.frame=CGRectMake(10, (frame1.size.height + 564), 300, 100);
credits.dataDetectorTypes=UIDataDetectorTypeAll;
credits loadHTMLString:creditsHtml baseURL:nil];
[scroll addSubview:credits];
}
-(BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType{
NSString *urls= jmaxString;
NSURL *requestURL =[NSURL URLWithString: urls];
if (([ [ requestURL scheme ] isEqualToString: @"http" ] || [ [ requestURL scheme ] isEqualToString: @"https" ] || [ [ requestURL scheme ] isEqualToString: @"mailto" ])
&& (navigationType == UIWebViewNavigationTypeLinkClicked)) {
return ![ [ UIApplication sharedApplication ] openURL: requestURL ];
}
return YES;
}
編輯shouldStartLoadWithRequest:方法
-(BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType{
NSURL *requestURL =[request URL];
if (([ [ requestURL scheme ] isEqualToString: @"http" ] || [ [ requestURL scheme ] isEqualToString: @"https" ] || [ [ requestURL scheme ] isEqualToString: @"mailto" ])
&& (navigationType == UIWebViewNavigationTypeLinkClicked)) {
return ![ [ UIApplication sharedApplication ] openURL: requestURL ];
}
NSLog(@"URL %@",requestURL);
return YES;
}
了錯誤NSURL *requestURL =[request URL];
與Expected ; at the end
& Extraneous ')' before ';'
如果換成'的OpenURL會發生什麼創建你的WebView學分低於該行:requestURL'用'的OpenURL:[requestURL URL]'? – Zakaria 2012-03-14 13:55:12
對不起,我忘記提到我的shouldStartLoadWithRequest:函數沒有被調用 – nithin 2012-03-14 13:59:05
請問,你可以發佈全班?我懷疑你忘了實現'UIWebViewDelegate'協議^^ – Zakaria 2012-03-14 14:05:15