APP で約 10 秒かかりますがloadHTMLString
、誰が問題を指摘できますか?
- (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]);
}
手を貸してください、なぜこんなに遅いloadHTMLString
のUIWebView
ですか?