ребята,
Я хочу сделать 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
Проблемы:
- На iOS 6 работает, но очень медленно.
- Он работает быстро на iOS 7, но иногда веб-просмотр ничего не показывает и отправляет это на консоль:
void SendDelegateMessage(NSInvocation *): делегату (webView:decidePolicyForNavigationAction:request:frame:decisionListener:) не удалось вернуться после ожидания 10 секунд. режим основного цикла выполнения: kCFRunLoopDefaultMode
Есть ли у вас какие-либо идеи, как я могу решить эту проблему? Есть ли другой способ сделать ту же работу?