효율성과 성능을 고려해 본 적이없는 셀을 다시로드하고 동시에 비디오 데이터 또는 HTML 데이터를 로컬에 캐시하면 셀을 재사용하고 셀에서 웹뷰를 다시로드해야합니다 . 반면에, 셀을 재생하려면 웹뷰의 객체를 기록하고,이 웹뷰를 재사용 된 셀에 직접 설정할 수 있습니다.
의사 코드 :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
YourCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier" forIndexPath:indexPath];
// If the video at this row is playing, just setup webview
UIWebView *webView = [self webviewOfPalyingForIndexPath: indexPath];
if (webView) {
[cell setupWithWebview: webView];
} else {
// Configure cell with reused webview
static UIWebView *publicWebview = [UIWebView new];
[cell setupWithWebview: publicWebview];
// Check if the data of webview is cached
NSData *cachedData = [self readCachedDataForIndexPath: indexPath];
if (cachedData) {
[cell setupWithCachedData:cachedData];
} else { // If not cached, load url and cach the data
[cell setupWithUrl: your_url];
[self cacheDataForUrl: your_url];
}
}
return cell;
}
// Record webview of playing at indexPath
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
YourCell *cell = (YourCell *)[tableView cellForRowAtIndexPath:indexPath];
[self recordPlayingWebView: cell.webview atIndexPath: indexPath];
}
내 대답은 당신을 위해 유용합니다 바랍니다.
UPDATE : 스위프트와
의사 코드 : 나는 쉽게하는 방법 당신의 문제를 해결하는 방법을 보여줄 수 있도록
let reusedWebview = UIWebView()
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("CellIdentifier", forIndexPath: indexPath)
// If the video at this row is playing, just setup webview
let webView = self.webviewOfPalyingForIndexPath(indexPath)
if (webView != nil) {
cell.setupWithWebview(webView)
} else {
// Configure cell with reused webview
cell.setupWithWebview(resuedWebview)
// Check if the data of webview is cached
let cachedData = self.readCachedDataForIndexPath(indexPath)
if (cachedData != nil) {
cell.setupWithCachedData(cachedData)
} else { // If not cached, load url and cach the data
cell.setupWithUrl(your_url)
self.cacheDataForUrl(your_url)
}
}
return cell;
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell = tableView.cellForRowAtIndexPath(indexPath)
self.recordPlayingWebView(cell.webview, forIndexPath: indexpath)
}
당신이 당신의 cellForRowAtIndexPath을 표시 할 수 있습니다. – pnizzle