NSMutableArray * scoreArray = [[[[returnedArr objectAtIndex:0]valueForKey:@"Questionnaire_Answers__r"] valueForKey:@"records"] valueForKey:@"Score__c"];
dispatch_async(dispatch_get_main_queue(), ^{
answerArray = [[[NSSet setWithArray:answerArray] allObjects] mutableCopy];
NSArray *filteredArray = [NSArray arrayWithArray:answerArray];
NSSortDescriptor *valueDescriptor = [[NSSortDescriptor alloc] initWithKey:@"scoreArray" ascending:NO]; // Describe the Key value using which you want to sort.
NSArray * descriptors = [NSArray arrayWithObject:valueDescriptor]; // Add the value of the descriptor to array.
answerArray = [[filteredArray sortedArrayUsingDescriptors:descriptors] mutableCopy]; // Now Sort the Array using descriptor.
[self.tblview reloadData];
});
我正在尝试使用此代码进行排序,但我正在崩溃。
答案 0 :(得分:-2)
NSSortDescriptor *valueDescriptor = [[NSSortDescriptor alloc] initWithKey:@"scoreArray" ascending:NO];
initWithKey:表示模型的var,而不是数组的名称。