0

彼ら、

一部のセルが Web ビューである UITableView を作成したいと考えています。

だから、私はそれらのhtmlをロードしました。

私のコード:

 NSString *md5HTML = [adm_post_dict[@"html"] MD5];

        SKWebViewCell *cell = [tableView dequeueReusableCellWithIdentifier:md5HTML];

        if (!cell) {
            cell = [[SKWebViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:md5HTML];

            cell.owner = self;
            cell.height = [adm_post_dict[@"height"] floatValue];
            cell.html = adm_post_dict[@"html"];
        }

        return cell;

SKWebViewCell.m:

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height)];
        [webView setScalesPageToFit:NO];
        webView.scrollView.scrollEnabled = NO;
        [self.contentView addSubview:webView];

        self.contentView.backgroundColor = [UIColor redColor];
    }
    return self;
}
- (void) prepareForReuse {
    [webView stopLoading];
}
- (void) setHeight:(float)height {
    webView.frame = CGRectMake(0, 0, self.contentView.frame.size.width, height);
}
- (void) setOwner:(NSObject<UIWebViewDelegate> *)owner {
    [webView setDelegate:owner];
}

- (void) setHtml:(NSString *)html {
    if (![_html isEqualToString:html]) {
        _html = html;

        [webView stopLoading];
        [webView loadHTMLString:[NSString stringWithFormat:@"<!DOCTYPE html><html><body>%@</body></html>",html] baseURL:[NSURL URLWithString:@"http://stylefie.com/"]];
    }
}


@end

問題:

  1. iOS 6 で動作しますが、非常に遅いです。
  2. iOS 7 では高速に動作しますが、Web ビューに何も表示されず、これがコンソールに送信されることがあります。

void SendDelegateMessage(NSInvocation *): デリゲート (webView:decidePolicyForNavigationAction:request:frame:decisionListener:) は、10 秒待った後に戻ることができませんでした。メイン実行ループ モード: kCFRunLoopDefaultMode

この問題を解決するにはどうすればよいですか?同じ作業を行う他の方法はありますか?

4

1 に答える 1

0

baseURL:nil を入れてみてください

[webView loadHTMLString:[NSString stringWithFormat:@"<!DOCTYPE html><html><body>%@</body></html>",html] baseURL:nil];
于 2013-10-28T20:56:06.197 に答える