Iphone 为什么UIWebView在使用UIWebView加载HtmlString时工作得如此缓慢?
在我的应用程序中加载HTMLSTRING大约需要10秒,谁能指出问题所在Iphone 为什么UIWebView在使用UIWebView加载HtmlString时工作得如此缓慢?,iphone,html,ios,uiwebview,Iphone,Html,Ios,Uiwebview,在我的应用程序中加载HTMLSTRING大约需要10秒,谁能指出问题所在 - (void)viewDidLoad { [super viewDidLoad]; webView = [[UIWebView alloc]initWithFrame:CGRectMake(10, 10, SCREEN_WIDTH, 480)]; [webView setBackgroundColor:[UIColor clearColor]]; [webView setOpaque:NO
- (void)viewDidLoad {
[super viewDidLoad];
webView = [[UIWebView alloc]initWithFrame:CGRectMake(10, 10, SCREEN_WIDTH, 480)];
[webView setBackgroundColor:[UIColor clearColor]];
[webView setOpaque:NO];
webView.delegate = self;
[scrollView addSubview:webView];
}
进入视图后,如果我收到消息:
- (void)updateJournalView:(NSArray *)journals {
NSString *descHtml = [self getHtmlDesc:journals];
[webView loadHTMLString:descHtml baseURL:nil];
}
getHtmlDesc
方法将快速返回html字符串
从加载日志中,您可以看到加载大约需要5秒钟
2012-11-26 20:34:35.322测试[8456:c07]====启动负载2012-11-26 12:34:35+0000:
2012-11-26 20:34:39.890试验[8456:c07]====完工荷载2012-11-26 12:34:39+0000:
以下是UIWebViewDelegate方法:
- (void)webViewDidFinishLoad:(UIWebView *)aWebView {
CGRect frame = aWebView.frame;
frame.size.height = 1;
aWebView.frame = frame;
CGSize fittingSize = [aWebView sizeThatFits:CGSizeZero];
frame.size = fittingSize;
aWebView.frame = frame;
scrollView.contentSize = CGSizeMake(SCREEN_WIDTH, fittingSize.height);
NSLog(@"====finish load %@:", [NSDate date]);
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType {
NSURL *url = [request URL];
if ([[url scheme] isEqualToString:@"redirect"] &&
[[url host] isEqualToString:@"opp_detail"]) {
NSString *oppIdStr = [[url path] stringByReplacingOccurrencesOfString:@"/player_id=" withString:@""];
if (oppIdStr && [oppIdStr length]) {
NSNumber *oppId = [NSNumber numberWithInt:[oppIdStr intValue]];
if ([oppId intValue] != gcontext.me.id) {
[screenNav gotoOppDetailScreen:[oppId intValue]];
}
}
}
return YES;
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType {
NSURL *url = [request URL];
if ([[url scheme] isEqualToString:@"redirect"] &&
[[url host] isEqualToString:@"opp_detail"]) {
NSString *oppIdStr = [[url path] stringByReplacingOccurrencesOfString:@"/player_id=" withString:@""];
if (oppIdStr && [oppIdStr length]) {
NSNumber *oppId = [NSNumber numberWithInt:[oppIdStr intValue]];
if ([oppId intValue] != gcontext.me.id) {
[screenNav gotoOppDetailScreen:[oppId intValue]];
}
}
}
return YES;
}
- (void)webViewDidStartLoad:(UIWebView *)webView{
NSLog(@"====start load %@:", [NSDate date]);
}
请帮我一个忙,为什么用
UIWebView
加载HTMLSTRING时速度会这么慢?如果没有什么繁重的内容需要渲染,那么在读取html字符串时可能会执行所有关于慢速磁盘操作的操作
请不要在ScrollView中添加webView,因为webView默认包含ScrollView。如果内容太长,无法以可见的webView大小表示,则webView将自动使用ScrollView来表示内容