Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios “';NSUnknownKeyException';,原因:…;此类不符合key scoreArray”;的键值编码;_Ios_Objective C_Iphone - Fatal编程技术网

Ios “';NSUnknownKeyException';,原因:…;此类不符合key scoreArray”;的键值编码;

Ios “';NSUnknownKeyException';,原因:…;此类不符合key scoreArray”;的键值编码;,ios,objective-c,iphone,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 = [[[

我正在尝试此代码进行排序,但我遇到了崩溃

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

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

显示您的scoreArray数据。@Mahesh我的scoreArray数据是3、1、2、4、0似乎您不了解排序描述符的工作原理:键不是数组的变量名,而是字典的键或数组中自定义类的属性。除非您知道KVC方法的作用,否则不要使用
valueForKey:
。首先调试代码并找到您的代码崩溃的地方?@VerveIOS由于initwithkey@“scoreArray”而崩溃
NSSortDescriptor *valueDescriptor = [[NSSortDescriptor alloc] initWithKey:@"scoreArray" ascending:NO];