我有一個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
向我們展示其餘代碼... –