0

私はjson文字列から解析されたテーブルビューを持っています。すべてがうまく機能します。検索バーに文字を入力する場合、このエラーが発生'-[__NSCFString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x1d52ac50'するのはコードです。以下の変数名データはNSMutableArrayです。

- (BOOL)searchDisplayController:(UISearchDisplayController *)controllershouldReloadTableForSearchString:(NSString *)searchString
    {
[searchData removeAllObjects];

NSArray *group;
for(group in nameData)
{
    NSLog(@"wat am i doing here:%@",group);
    NSMutableArray *newGroup = [[NSMutableArray alloc] init];
    NSString *element;

    for(element in group)
    {
        NSRange range = [element rangeOfString:searchString options:NSCaseInsensitiveSearch];

        if (range.length > 0) {
            [newGroup addObject:element];
        }
    }

    if ([newGroup count] > 0) {
        [searchData addObject:newGroup];
    }

}

return YES;
 }
4

1 に答える 1

1

このコードをチェックしてください

 - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
    NSMutableArray *array=[[NSMutableArray alloc]init];
    NSDictionary *naming= [self.friendsDictionary objectForKey:@"data"];
    NSLog(@"ggg %@",[self.friendsDictionary objectForKey:@"data"]);
    for(int i =0 ; i< [[self.friendsDictionary objectForKey:@"data"] count]; i++){
        [array addObject:[[[self.friendsDictionary objectForKey:@"data"] objectAtIndex:i] objectForKey:@"name"]];
    }
    NSLog(@"Array %@", array);

    if(self.searchDisplayController.searchBar.text.length>0) 
    {
        NSString *strSearchText = self.searchDisplayController.searchBar.text;
        NSMutableArray *group = [[NSMutableArray alloc]init];
        for (int i=0; i<array.count; i++) {

            NSString *strData = [array objectAtIndex:i]; 
              NSLog(@"string Data:%@",strData);
            NSRange rng = [strData rangeOfString:strSearchText options:NSCaseInsensitiveSearch];
            if(rng.location != NSNotFound)
            {
                if(rng.location== 0)//that is we are checking only the start of the names.
                {
                    [group addObject:strData]; 
                }
            }
        }
        if ([group count] > 0) 
        {
    searchData = [[NSMutableArray alloc] init];
            [searchData addObjectsFromArray:group];
            NSLog(@"Sear %@", searchData);

        }
    } 
    return YES;
  }
于 2012-07-27T10:59:29.620 に答える