“' NSUnknownKeyException',原因:...此类不是密钥值编码兼容的密钥scoreArray”

时间:2016-11-22 07:03:26

标签: ios objective-c iphone

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];
    });

我正在尝试使用此代码进行排序,但我正在崩溃。

1 个答案:

答案 0 :(得分:-2)

NSSortDescriptor *valueDescriptor = [[NSSortDescriptor alloc] initWithKey:@"scoreArray" ascending:NO]; 

initWithKey:表示模型的var,而不是数组的名称。