NSUnknownKeyException原因:'[<store 0x17572b80 =“”> valueForUndefinedKey:]:此类与密钥名称不符合密钥值</store>

时间:2014-01-09 12:05:22

标签: ios7 xcode5 nspredicate container-classes

我正在开发一个在联系人列表上方创建搜索栏的应用程序。如果我按下搜索栏,应用程序就会崩溃。我调试了应用程序,发现崩溃发生在此行。 filteredCandyArray = [NSMutableArray arrayWithArray:[candyArray filteredArrayUsingPredicate:predicate]];

我在我的程序中正在做的是我正在获取所有联系人(名称,编号和图像)并添加到数组(candyArray)。但是当我尝试执行NSPredicate操作时,我收到此消息并且应用程序崩溃时给出以下消息。

  

wetwert [2380:60b] *由于未捕获的异常'NSUnknownKeyException'而终止应用程序,原因:'[valueForUndefinedKey:]:此类不是密钥值的密钥值编码兼容。   * 第一次抛出调用堆栈:   (0x2d51ae83 0x378776c7 0x2d51ab89 0x2ded6e3f 0x2de3c139 0x2de7a3f7 0x2de79fb5 0x2de79083 0x2de7901f 0x2de78e2d 0x27d23 0x27f37 0x2fe92b79 0x2fcd3da3 0x2fcd3d3f 0x2fcd3d13 0x2fcbf743 0x2fe928ed 0x2fcdd8b1 0x2fe53b67 0x2fe5310f 0x2fe92727 0x2fe52e2d 0x2de49aa5 0x2fce1485 0x2fe52d5f 0x2fcc9049 0x2defee4b 0x2d4e5f1f 0x2d4e53e7 0x2d4e3bd7 0x2d44e471 0x2d44e253 0x321882eb 0x2fd03845 0x28451 0x37d70ab7)   libc ++ abi.dylib:以NSException类型的未捕获异常终止

我正在提供添加到array.below

的代码
 for (int i=0; i<_contactsarray.count; i++) {

    [candyArray addObject:[store candyofcategory:[_contactsarray objectAtIndex:i] phone:[_numbersarray objectAtIndex:i] image:[_imagesarray objectAtIndex:i]]];

其中3个数组包含姓名,电话号码。和图像。 被调用的方法如下所示。

+(id)candyofcategory:(NSString *)name phone:(NSString *)phone image:(UIImage *)image{
    store *newstore=[[self alloc]init];
    newstore.c_name=name;
    newstore.c_phone=phone;
    newstore.cnt_image=image;

    return newstore;
}

这个方法在一个类'store'中,它是NSObject类。我能够获取数据并在tableview中显示,但是当我在这个数组上调用谓词操作时,我得到了一个崩溃。关于这个问题的任何想法?我在下面添加谓词方法

-(void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope {
    // Update the filtered array based on the search text and scope.
    // Remove all objects from the filtered search array
    [self.filteredCandyArray removeAllObjects];
    // Filter the array using NSPredicate
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.name contains[c] %@",searchText];
    filteredCandyArray = [NSMutableArray arrayWithArray:candyArray];
    filteredCandyArray = [NSMutableArray arrayWithArray:[candyArray filteredArrayUsingPredicate:predicate]];
}

1 个答案:

答案 0 :(得分:7)

如果我看到它正确,store有一个属性“c_name”(而不是“name”)。 所以你应该在谓词中使用

[NSPredicate predicateWithFormat:@"SELF.c_name CONTAINS[c] %@",searchText]
相关问题