我想用NSPredicate過濾數組,我有一些問題。NSPredicate:發送到實例的無法識別的選擇器
我有一個名爲「食譜」的NSArray保存我的數據。
這裏我的代碼:
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
NSPredicate *resultPredicate = [NSPredicate
predicateWithFormat:@"SELF contains[cd] %@",
searchText];
NSArray *searchRecipe = self.recipe[0];
searchResults = [searchRecipe filteredArrayUsingPredicate:resultPredicate];
}
當我運行這段代碼,我得到以下錯誤:
2014-01-20 15:40:16.729 Recipes Editor[909:60b] -[filteredArrayUsingPredicate:]: unrecognized selector sent to instance 0x15666f80
2014-01-20 15:40:16.735 Recipes Editor[909:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[filteredArrayUsingPredicate:]: unrecognized selector sent to instance 0x15666f80'
*** First throw call stack:
(0x2f997f4b 0x39dd86af 0x2f99b8e7 0x2f99a1cb 0x2f8e94d8 0x12d01 0x12eeb 0x322fe3d9 0x3213f713 0x3213f6b3 0x3213f691 0x3212b11f 0x322fe149 0x321491cf 0x322bf261 0x322be807 0x322fdf77 0x322be525 0x302c67db 0x3214cdd9 0x322be453 0x32134a49 0x3037be9b 0x2f963183 0x2f962653 0x2f960e47 0x2f8cbc27 0x2f8cba0b 0x345f2283 0x3216f049 0x130c1 0x3a2e0ab7)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
爲什麼filteredArrayUsingPredicate不能過濾我的陣列?
THX
'self.recipe [0]'似乎不是'NSArray'本身。但打開調試信息,問題會自行公開。 – 2014-01-20 14:46:59
是否定義了searchBeacon? – revolver
是的,searchBeacon是一個錯誤。但我有同樣的錯誤。 – testoverblaireau