Uitableview NSFETCH请求核心数据

Uitableview NSFETCH请求核心数据,uitableview,core-data,nsfetchedresultscontroller,Uitableview,Core Data,Nsfetchedresultscontroller,我正在处理核心数据,并将一个NSMutableArray保存到一个可转换属性,我使用NSFetchRequest准备一个NSArray,该数组用于填充UITableView,看起来很简单。我还使用NSFetchedResultsController作为节名。 节使用标题ForHeaderInSection以正确的方式填充: 我的UITableViewCell是一个不同的故事。我使用下面的代码获取 AppDelegate appDel = [UIApplication sharedApplicat

我正在处理核心数据,并将一个
NSMutableArray
保存到一个可转换属性,我使用
NSFetchRequest
准备一个
NSArray
,该数组用于填充
UITableView
,看起来很简单。我还使用
NSFetchedResultsController
作为节名。 节使用标题ForHeaderInSection以正确的方式填充: 我的
UITableViewCell
是一个不同的故事。我使用下面的代码获取

AppDelegate appDel = [UIApplication sharedApplication].delegate;
NSManagedObjectContext  context = appDel.managedObjectContext;
NSFetchRequest  fetch = [[NSFetchRequest alloc]init];
NSEntityDescription carEntity = [NSEntityDescription entityForName:"CarDocType" inManagedObjectContext:context];
[fetch setEntity:carEntity];
docTypeToDisplay = [[appDel.managedObjectContext executeFetchRequest:fetch error:&error]mutableCopy];
我还让用户在每个部分中用不同数量的行填充该部分,因此在我的cellForRowAtIndexPath中我正在这样做

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  static NSString cellID = "Cell";
    UITableViewCell cell = [tableView dequeueReusableCellWithIdentifier:cellID];
     cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];

   cell.textLabel.text = [docTypeToDisplay objectAtIndex:indexPath.section][indexPath.row];
  return cell;
}
当我尝试从此调用返回单元格时,
cell.textlab.text=[docTypeToDisplay objectAtIndex:indexath.section][indexPath.row]
我正在抛出一个异常,它正在查找字符串。因此,当我将
NSArray
转换为
NSString

NSString carTitle = [NSString stringWithFormat:",docTypeToDisplay];

NSString carTitle = [NSString stringWithFormat:",carDocMset];
cell.textLabel.text = carTitle;
return cell;
我得到了整个字符串,不仅仅是名称,它看起来像这样

(entity: CarDocType; id: 0xd000000000040002 <x-coredata://AB5BF8F9-5166-4A11-AA69-30962EEAE745/CarDocType/p1> ; data: {  cardocumenttype    \\\"Driver License\\\"\\n)\  })
(实体:CarDocType;id:0xd000000000040002;数据:{CardDocumentType\\\\\\\“驾驶执照\\\\”\\n)\}
我只是想要驾驶执照,我知道我丢了什么东西。有人能告诉我是什么吗

问候
JZ

当已有一个
NSFetchedResultsController
获取结果时,为什么要使用
NSArray
来获取结果?当执行fetchRequest时,它会返回一个
NSManagedObject
数组
docTypeToDisplay[indexPath.row]
返回
CarDocType
对象。考虑到实体:
CarDocType
有一个属性:
driverLicense
NSString*driverLicense=docTypeToDisplay[indexPath.row]。driverLicense
。为什么不使用
NSFetchedResultController
for
cellForRowAtIndexPath:
最好使用关系而不是数组。此外,要创建
NSString
您没有提供插入值的格式的出口,因此即使您提取数据,它也不会显示。更改语法以设置字符串:
NSString*carTitle=[nsstringstringwithformat:@“%@”,carDocMset]对于索引到数组和获取结果控制器,您似乎相当困惑。您显示的代码在索引到数组中时看起来应该崩溃。那是真的复制粘贴吗?你真的应该显示FRC的详细信息,并使用它填充单元格…感谢各位的输入,我已经远离了这一点,将再看一看,并使用您的反馈。问候JZ