2014-01-09 27 views
1

我正在卸載在聯繫人列表上創建搜索欄的應用程序。如果我按搜索欄應用程序得到崩潰。我調試了應用程序,發現崩潰在這條線上發生。 filteredCandyArray = [NSMutableArray arrayWithArray:[candyArray filteredArrayUsingPredicate:predicate]];NSUnknownKeyException原因:'[<store 0x17572b80> valueForUndefinedKey:]:該類不是關鍵字編碼兼容的密鑰名稱

我在我的程序中做的是我抓取所有聯繫人(姓名,號碼和圖片),並添加到數組(糖果陣列)。但是當我嘗試做一個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; 
} 

此方法是在一類「存儲」是NSObject的class.Im的能夠在一個的tableview數據和顯示取,但是當我把這種陣列上的謂詞的操作,得到了一個crash.Any關於這個問題的想法?林添加判斷方法如下

-(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

請出示代碼'predict'。 –

+0

我已經編輯了問題在最後的方法任何想法? –

+1

查馬丁的答案。 –

回答

7

如果我沒有看到它,store有一個屬性「c_name」(而不是「名」)。 所以,你應該在謂語使用

[NSPredicate predicateWithFormat:@"SELF.c_name CONTAINS[c] %@",searchText] 
+0

謝謝兄弟。你救了我的一天... –

+0

這樣一個簡單的問題。浪費了很多時間。馬丁......你是男人。謝謝! – iTrout

相關問題