Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 核心数据获取到许多_Iphone_Objective C_Ios_Core Data - Fatal编程技术网

Iphone 核心数据获取到许多

Iphone 核心数据获取到许多,iphone,objective-c,ios,core-data,Iphone,Objective C,Ios,Core Data,我试图获取所有类别及其子类别,并将它们全部显示在表中。我知道如何获取所有类别,但我需要获取所有子类别,并使用“获取结果”控制器按类别对它们进行排序。有什么建议吗 因此,在fetchedResultsController.fetchedObject中有类别 由于每个子类别基本上都包含在类别中,因此可以通过调用[Category valueForKey:@“subCategory” 这将为您提供一个NSSet,然后您可以对其进行排序(到NSArray),并将其用作tableView的数据 但是,它不

我试图获取所有类别及其子类别,并将它们全部显示在表中。我知道如何获取所有类别,但我需要获取所有子类别,并使用“获取结果”控制器按类别对它们进行排序。有什么建议吗


因此,在fetchedResultsController.fetchedObject中有类别

由于每个子类别基本上都包含在类别中,因此可以通过调用
[Category valueForKey:@“subCategory”

这将为您提供一个NSSet,然后您可以对其进行排序(到NSArray),并将其用作tableView的数据


但是,它不会包含在fetchedResultsController中。

您可以创建一个FetchedResults控制器,用于获取子类别实体,并根据类别将其分组到节中:

然后可以使用中所述的常用表视图数据源方法


这为您提供了一个表视图,每个类别有一个表视图部分。

如果您有选择,您也可以用其他方式来完成

获取arrayOfCategories中的所有类别对象

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection (NSInteger)section:


{
    Category *cat = [ arrayOfCategories objectAtIndex:indexPath.row]

   if(arrayToHoldObjects.count > 0)

{

[arrayToHoldObjects removeAllObject];
}


for(Subcategory *sub in Category.subcategory)

{
   [arrayToHoldObjects addObject:sub];

}

  return arrayToHoldObjects.count;


}

- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath {


  Category *cat = [ arrayOfCategories objectAtIndex:indexPath.row]

   if(arrayToHoldObjects.count > 0)

{

[arrayToHoldObjects removeAllObject];
}


for(Subcategory *sub in Category.subcategory)

{
   [arrayToHoldObjects addObject:sub];

}

   Subcategory *sub = [arrayToHoldObjects objectAtIndexPath.row]  

   for(int k =0 ; k < arrayToHoldObjects .count; k++)
  {

    // do what ever u like with sub  

     return cell;

   }



}
-(NSInteger)表视图:(UITableView*)表视图行数节(NSInteger)节:
{
Category*cat=[arrayOfCategories对象索引:indexPath.row]
如果(arrayToHoldObjects.count>0)
{
[arrayToHoldObjects removeAllObject];
}
用于(类别中的子类别*子类别)
{
[arrayToHoldObjects添加对象:sub];
}
返回arrayToHoldObjects.count;
}
-(UITableView单元格*)表格视图:(UITableView*)表格视图
cellForRowAtIndexPath:(NSIndexPath*)indexPath{
Category*cat=[arrayOfCategories对象索引:indexPath.row]
如果(arrayToHoldObjects.count>0)
{
[arrayToHoldObjects removeAllObject];
}
用于(类别中的子类别*子类别)
{
[arrayToHoldObjects添加对象:sub];
}
子类别*sub=[arrayToHoldObjects objectAtIndexPath.row]
for(int k=0;k
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection (NSInteger)section:


{
    Category *cat = [ arrayOfCategories objectAtIndex:indexPath.row]

   if(arrayToHoldObjects.count > 0)

{

[arrayToHoldObjects removeAllObject];
}


for(Subcategory *sub in Category.subcategory)

{
   [arrayToHoldObjects addObject:sub];

}

  return arrayToHoldObjects.count;


}

- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath {


  Category *cat = [ arrayOfCategories objectAtIndex:indexPath.row]

   if(arrayToHoldObjects.count > 0)

{

[arrayToHoldObjects removeAllObject];
}


for(Subcategory *sub in Category.subcategory)

{
   [arrayToHoldObjects addObject:sub];

}

   Subcategory *sub = [arrayToHoldObjects objectAtIndexPath.row]  

   for(int k =0 ; k < arrayToHoldObjects .count; k++)
  {

    // do what ever u like with sub  

     return cell;

   }



}