【发布时间】:2017-07-21 06:41:31
【问题描述】:
我想在 UITableViewCell 中嵌入 UIWebView。但是也有一些问题:
1,我在方法中设置单元格的数据库:
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell * cell = [tableView
dequeueReusableCellWithIdentifier:cellIdenWebViewIntro
forIndexPath:indexPath];
PlayListModel * model = [PlayListModel new];
cell.model = model;
return cell;
}
在单元格中,我设置 webView 并在 setModel 方法中发送 url 请求:
- (void)setModel:(PlayListModel *)model{
_model = model;
NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://temp url"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10];
[self.webView loadRequest:request];
}
这是配置单元的一种非常正常的方式。但是当tableView向下滚动并滚动回webViewCell时,系统再次调用(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath,所以webView会一次又一次地发送url请求。所以有办法缓存webView的HTML内容。如果用户没有弹出当前视图控制器,我将为 webView 重用 HTML,但不会多次发送请求。
p.s 我在创建 NSURLRequest 时已经设置了缓存策略,但是它不起作用。
【问题讨论】:
标签: ios objective-c uitableview