我正在嘗試使用searchController進行篩選。我正在逐漸線NSRange productNameRange = NSMakeRange(0, [[_list valueForKey:@"name"] length]);
崩潰(-[__NSArrayI length]: unrecognized selector sent to instance
)在下面的代碼:- [__ NSArrayI長度]:嘗試使用searchController進行篩選時崩潰
-(void)updateFilteredContent:(NSString*)searchText {
// Update the filtered array based on the search text and scope.
[self.searchResults removeAllObjects];
// Filter the array using NSPredicate
NSLog(@"_categories are %@",_categories);
for (NSDictionary *object in _categories) {
NSUInteger searchOptions = NSCaseInsensitiveSearch | NSDiacriticInsensitiveSearch;
NSRange productNameRange = NSMakeRange(0, [[_list valueForKey:@"name"] length]);
NSRange foundRange = [[_list valueForKey:@"name"] rangeOfString:searchText options:searchOptions range:productNameRange];
if (foundRange.length > 0) {
[self.searchResults addObject:object];
}
}
}
我試過if語句像if ([[object valueForKey:@"name"] length] >0){
長度增加了,但它仍然崩潰。
的日誌_list的一個例子是:
_list names are (
"Honda",
"Ford",
Toyota,
你覺得'[_list valueForKey:@「name」]'return? – 2015-01-21 03:58:47
通過退貨,你的意思是類的類型? – user3411663 2015-01-21 04:05:17
valueForKey:返回數組... [[_list valueForKey:@「name」] [0] length];嘗試像這樣.. – TamilKing 2015-01-21 04:27:54