Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
516 views
in Technique[技术] by (71.8m points)

iphone - NSCFString countByEnumeratingWithState:objects:count: ERROR while searching NSMutableArray

I have the following situation where I have an NSMutableArray filled with an xml file which I want to search. When I enter something in the search field I get this Error:

-[NSCFString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x5b388b0

What does it means and how can I fix it??

I suppose the error is somewhere around here.

- (void)searchTableView{

 searchedList = [[NSMutableArray alloc] init];
 NSLog(@"new list %@", searchedList);
 NSString *searchText = searchBar.text;
 NSMutableArray *searchArray = [[NSMutableArray alloc] init];

 for (NSDictionary *dictionary in list) {
    NSArray *array = [dictionary objectForKey:@"TITLE"];
   [searchArray addObjectsFromArray:array];
 }

 for (NSString *TempArray in searchArray) {
  NSRange titleResults = [TempArray rangeOfString:searchText options:NSCaseInsensitiveSearch];
  if (titleResults.length > 0) 
  [searchedList addObject:TempArray];
 }
 [searchArray release];
 searchArray = nil;
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

it means you are calling a method designed for an NSArray (countByEnumeratingWithState:objects:count on a NSString.

I don't know ifthis code is copy/paste from yours, but if so, at the end where you use [searchList addObject:TempArray] you don't have an object named searchList.

Also, work on your naming conventions. big time.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...