2015-01-21 50 views
-1

我正在嘗試使用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, 
+1

你覺得'[_list valueForKey:@「name」]'return? – 2015-01-21 03:58:47

+0

通過退貨,你的意思是類的類型? – user3411663 2015-01-21 04:05:17

+0

valueForKey:返回數組... [[_list valueForKey:@「name」] [0] length];嘗試像這樣.. – TamilKing 2015-01-21 04:27:54

回答

0

你[_list valueForKey:@ 「名」]返回一個NSArray,這應該是一個NSString來計算它的長度..

0

請檢查這種情況,並讓我知道它是否仍然崩潰!

if([_list allkeys] contains @"name"]) 
{ 
    NSString *tempStr = [_list valueForKey:@"name"]; 
} 
if(tempStr) 

NSRange productNameRange = NSMakeRange(0, [tempStr length]); 
相關問題