我有一个带有自定义单元格的 UITableView,我在解析 xml 数据后填充(使用数组信息服务)。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
ApplicationCell *cell = (ApplicationCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[self.cellNib instantiateWithOwner:self options:nil];
cell = tmpCell;
self.tmpCell = nil;
}
infoService *e = [self.infoservices objectAtIndex:indexPath.row];
cell.name = [e infoName];
NSString *infodetails = [e infoDetails];
if ( infodetails == nil ) {
cell.details = @"Loading...";
[self startInfoDownload:e forIndexPath:indexPath];
NSLog(@"Loading...");
} else {
cell.details = infodetails;
NSLog(@"Show info detail: %@", infodetails );
}
return cell;
}
- (void)infoDidFinishLoading:(NSIndexPath *)indexPath
{
infoDownloader *infoserv = [imageDownloadsInProgress objectForKey:indexPath];
if (infoserv != nil)
{
[infoservices replaceObjectAtIndex:[indexPath row] withObject:infoserv.appRecord];
NSIndexPath *a = [NSIndexPath indexPathForRow:indexPath.row inSection:0]; // I wanted to update this cell specifically
ApplicationCell *cell = (ApplicationCell *)[self.tableView cellForRowAtIndexPath:a];
cell.details = [[infoservices objectAtIndex:[indexPath row]] infoDetails];
NSLog(@"Updating=%@", [[infoservices objectAtIndex:[indexPath row]] infoDetails]);
}
}
对于每个单元格,我使用 NSURLConnection sendAsynchronousRequest 从对象 infoDownloader 检索和解析 xml 数据
- (void)startDownload
对于每个单独的单元格。
成功解析数据后,调用来自 infoDownloader 的委托方法
- (void)infoDidFinishLoading:(NSIndexPath *)indexPath
问题是,虽然
- (void)infoDidFinishLoading:(NSIndexPath *)indexPath
在解析每个单元格后被调用,我可以看到
NSLog(@"Updating=%@", [[infoservices objectAtIndex:[indexPath row]] infoDetails]);
在具有正确详细信息的调试器中,单元格不会立即刷新,而是在 6 或 7 秒后刷新。也不会调用 cellForRowAtIndexPath
- (void)infoDidFinishLoading:(NSIndexPath *)indexPath
出于某种原因,因为在 infoDidFinishLoading 之后没有调试输出。我也不明白 cell.details 是如何实际刷新的,因为 cellForRowAtIndexPath 不再被调用。
我尝试使用 Apple 的 LazyTableImages 加载示例设置此功能,我已成功使用该示例,但我不知道出了什么问题。