0
我正在用CoreData更新UITableView。在启动时,第一行显示为(空)。如果我向下滚动/向上,它会加载。它只是不显示最初。UITableView显示(空)第一行
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
[cell setAccessoryType: UITableViewCellAccessoryDisclosureIndicator];
}
// set text for each cell
[cell.textLabel setText: [dataManager getProjectValueForKey: @"Title" atIndex: [indexPath row]]];
[cell.detailTextLabel setText: [[[dataManager getProjectValueForKey: @"pid" atIndex:[indexPath row]] stringByAppendingString: @": "] stringByAppendingString: [dataManager getProjectValueForKey: @"Sponsor" atIndex:[indexPath row]]]];
return cell;
}
dataManager
是什么在跟Core Data交谈。我觉得它可能会落后或者在启动时发生什么,所以单元试图在数据准备好之前显示数据。但我不知道。
如果您将第一个单元格关闭并返回到屏幕上,是否会加载正确的文本?此外,您可能需要查看NSFetchedResultsController以使用Core Data结果填充您的UITableView。其设计和高度优化的用例。 –
是的,他们按照操作中提到的那样做。我有点新鲜。 –
很难说出发生了什么事。我会在'-tableView:cellForRowAtIndexPath:'中设置一个断点。第一次,进入'-getProjectValueForKey:atIndex:',看看它为什么会回到零。 –