【发布时间】:2014-07-08 07:06:03
【问题描述】:
我有存储在 Core Data 中的品牌列表,每个品牌都与多个内容相关联。内容有一个名为downStatus 的标志,用于表示是否下载了内容。以下方法用于从 Core 数据中获取按品牌名称排序的所有品牌
-(void)getDownloadedBrands{
AppDelegate *aAppDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
NSMutableArray *aBrands = [[NSMutableArray alloc] init];
NSEntityDescription *entity =
[NSEntityDescription entityForName:@"Brand" inManagedObjectContext:aAppDelegate.managedobjectcontext];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entity];
NSSortDescriptor *sort=[[NSSortDescriptor alloc]initWithKey:@"brandName" ascending:YES];
//NSSortDescriptor *sort1=[[NSSortDescriptor alloc]initWithKey:@"downStatus" ascending:YES];
[request setSortDescriptors:[NSArray arrayWithObjects:sort, nil]];
aBrands =(NSMutableArray *)[aAppDelegate.managedobjectcontext executeFetchRequest:request error:nil];
[request release];
[sort release];
NSLog(@"%@",aBrands);
brands = [[NSMutableArray alloc]initWithArray:aBrands];
aAppDelegate.dbBrandArr = brands;
[self loadGridView];
}
现在我想使用内容中的downStatus 进行排序。因此,就像按字母顺序下载的品牌,然后按字母顺序未下载的品牌。 downStatus 采用两个值 1 表示已下载 0 表示未下载。请帮忙。
【问题讨论】:
标签: objective-c core-data nssortdescriptor