Iphone 从2个实体获取的ResultsController
我正在学习CoreData,并开始在我的一个项目中使用它 我使用Iphone 从2个实体获取的ResultsController,iphone,core-data,nsfetchedresultscontroller,Iphone,Core Data,Nsfetchedresultscontroller,我正在学习CoreData,并开始在我的一个项目中使用它 我使用fetchedResultsController从CoreData中获取数据,以填充uitableview即可 我遇到的问题是,我需要从2个实体填充1个表。 这就是我现在拥有的 NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entit
fetchedResultsController
从CoreData中获取数据,以填充uitableview
即可
我遇到的问题是,我需要从2个实体填充1个表。
这就是我现在拥有的
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Contact" inManagedObjectContext:delegate.managedObjectContext];
[fetchRequest setEntity:entity];
这将只从“Contact”实体获取数据,但我还需要用“Category”实体的数据填充表。我不知道该怎么做
基本上是最终结果,我想让tableview
显示如下内容
(假设联系人有3项,类别有2项)
uiTableindex0:获取联系人0
uiTableindex1:获取联系人1
uiTableindex2:获取联系人2
uiTableindex3:fetchCategory 1
uiTableindex4:fetchCategory 2
@Suwitcha Sugthana在这种情况下,我建议您将来自两个不同实体的数据填充到两个不同的数组中,假设它们是(myArray1和myArray2),方法是将它们设置为不同的
NSFetchRequest
对象。并在单元格上打印两个数组,如下所示
if(indexPath.row<[myArray1 count])
{
cell.text=[myArray1 objectAtIndex:indexPath.row];
}
else
cell.text=[myArray2 objectAtIndex:(indexPath.row-[myArray1 count])]
//myArray1 has data of contact
//myArray2 has data of catagory
if(indexPath.row)
if(indexPath.row<[myArray1 count])
{
cell.text=[myArray1 objectAtIndex:indexPath.row];
}
else
cell.text=[myArray2 objectAtIndex:(indexPath.row-[myArray1 count])]
//myArray1 has data of contact
//myArray2 has data of catagory