我有一个UITableView每个单元格显示我想要的物品是那种在我的名单,但这些菜单项没有从一个数组,而是来自一个数据库对象独特的菜单项排序数据库对象
例子:
cellForRowAtIndexPath{
Menus_Items *menuItem = [menuCategory.hasMenuItems.allObjects objectAtIndex:indexPath.row];
lblMenuItemName.text = menuItem.name;
}
如何对菜单项进行排序?如果它是一个阵列,我本可以做到的,即
NSSortDescriptor *orderSort = [[NSSortDescriptor alloc] initWithKey:@"order" ascending:NO];
// String are alphabetized in ascending order
NSSortDescriptor *strNameSort = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
// Combine the two
NSArray *sortDescriptors = @[orderSort, strNameSort];
arrCategories = [DatabaseHelper getAllData:@"Menus_cat" offset:0 predicate:[NSPredicate predicateWithFormat:@"ofOutlet == %@",outletsObject] sortDescriptor:nil];
// sortedArrayUsingDescriptor is the method use to sort an array which is having multiple parameters in sort descriptor
arrCategories = [arrCategories sortedArrayUsingDescriptors:sortDescriptors];
请帮忙。在此先感谢
为什么不在排序时排序? – limon
我试过,但它在循环中效果不好 – user3504436
向我们展示其余代码... –