首页>>iPhone >>开发
iOS开发资料收集 – UIWebView
楼:1
九品仙
2011-9-11 23:41:01
iOS开发资料收集 – UIWebView

附注:最近一个月一直在做一个项目,花去每天所有的空余时间,包括思考的时间。没有时间写新文章,只好将以前的旧文贴过来,真是汗颜。这个阶段得持续到下个月中。唉~~~

载入HTML 1
?Download download.txt
1234
NSString *resourcePath = [[NSBundle mainBundle] resourcePath];NSString *filePath = [resourcePath stringByAppendingPathComponent:@"webpage.html"];NSString *htmlstring=[[NSString alloc] initWithContentsOfFile:filePath  encoding:NSUTF8StringEncoding error:nil];[uiwebview loadHTMLString:htmlstring baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];
载入HTML 2
?Download download.txt
12
NSString *webpage = [NSBundle pathForResource:@"webpage" ofType:@"html" inDirectory:[[NSBundle mainBundle] bundlePath]];[uiwebview loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:webpage]]];
载入HTML 3
?Download download.txt
1
[uiwebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://zgia.net/"]]];
点击链接使用Safari打开

添加UIWebViewDelegate代理

?Download download.txt
123456789101112131415
uiwebview.delegate = self; #pragma mark -#pragma mark UIWebViewDelegate- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{if(navigationType ==  UIWebViewNavigationTypeLinkClicked) {[[UIApplication sharedApplication] openURL:request.URL];return NO;}else{return YES;}}