3
在iOS6應用程序中,我使用CoreData從數據庫中獲取NSManagedObjects,並將它們顯示在tableViewCell中。我的問題是,與初始滾動位置之外的單元格相對應的所有對象都處於故障狀態,並且不會恢復原狀。我看不到我的錯誤。CoreData對象沒有受到損害
fetchRequest.returnsObjectsAsFaults = NO;有幫助,但我想要一個乾淨的解決方案。
下面是代碼:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ContactsCell";
ContactsCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
Contact *contact = [self.contacts objectAtIndex:indexPath.row];
//here some contacts are faulted. contact.name is null if I fetch it
[cell setContactData:contact];
return cell;
}
這裏是我取(用Restkit 0.10.3):
NSFetchRequest *fetchRequest = [Contact fetchRequest];
fetchRequest.sortDescriptors = [self sortDescriptors];
fetchRequest.returnsObjectsAsFaults = NO;
return [Contact objectsWithFetchRequest:fetchRequest];
[聯繫objectsWithFetchRequest:fetchRequest]。是Restkit 0.10.x的擴展。在0.20版本中,他們刪除了這些代碼,開發人員現在必須使用Core Data語法。 – netshark1000 2013-12-02 10:02:56