我有一个带有自定义单元格的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不会再次被调用。
我试着使用苹果的LazyTableImages加载示例来设置这个功能,我已经成功地使用了它,但我不知道出了什么问题。
发布于 2013-03-21 17:40:56
任何影响UI的更改都必须在主线程上执行。
正在刷新tableView,通过更改单元格详细信息、重新加载选项卡视图、重新加载行...是否有影响UI的更改。
特别是,您应该使用以下命令在主线程中执行更改:
dispatch_async(dispatch_get_main_queue(), ^{
cell.details = [[infoservices objectAtIndex:[indexPath row]] infoDetails];
}或iOS 4之前的版本:
cell performSelectorOnMainThread:@selector(setDetails:) withObject:[[infoservices objectAtIndex:[indexPath row]] infoDetails];https://stackoverflow.com/questions/10084373
复制相似问题