Uitableview TableView UISearchBar在搜索时崩溃

Uitableview TableView UISearchBar在搜索时崩溃,uitableview,nsmutablearray,uisearchbar,nsmutabledictionary,Uitableview,Nsmutablearray,Uisearchbar,Nsmutabledictionary,我一直在玩我的应用程序表视图的搜索工具,现在试图让它工作,但我在控制台中不断得到相同的错误 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“[NSCFDictionary rangeOfString:选项:]:无法识别的选择器发送到实例 数据源是从字典中获取itz值的数组。。。。 tableData将存储将在表中显示的数据。 问: 假设我有一个字典,其中有5个值,每个值对应不同的键。。然后我把字典放在一个数组中。该数组可以用作搜索的数据源吗?我使用

我一直在玩我的应用程序表视图的搜索工具,现在试图让它工作,但我在控制台中不断得到相同的错误

由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“[NSCFDictionary rangeOfString:选项:]:无法识别的选择器发送到实例

数据源是从字典中获取itz值的数组。。。。 tableData将存储将在表中显示的数据。 问: 假设我有一个字典,其中有5个值,每个值对应不同的键。。然后我把字典放在一个数组中。该数组可以用作搜索的数据源吗?我使用cellForRowAtIndexPath中的相同数组来显示单元格中的数据

Plz建议使用代码片段

这是我的textDidChange代码

    -(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
    {   
        [tableData removeAllObjects];// remove all data that belongs to previous search

        if([searchText isEqualToString:@""]){
            searchText==nil;
            [tableview reloadData];     
            return;     
        }

        NSInteger counter = 0;  
        for(NSString *name in dataSource)       
        {       
            NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];      
            NSRange r = [name rangeOfString:searchText options:NSCaseInsensitiveSearch];        
            if(r.location != NSNotFound)            
            {           
                if(r.location== 0)//that is we are checking only the start of the names.                
                {               
                    [tableData addObject:name];             
                }           
            }       
            counter++;      
            [pool release];     
        }   
        [tableview reloadData]; 
    }

尝试附加条件

    if([searchText isEqualToString:@""] || searchText == nil){
    }
让我知道,这对你有用吗

如果数据源是您的NSMutableArray

    for (int i = 0; i < [dataSource count]; i++)
    {
        NSMutableDictionary *temp = (NSMutableDictionary*) [dataSource objectAtIndex:i];
        NSString *name = [NSString stringWithFormat:@"%@", [temp valueForKey:@"name"]];
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];      
        NSRange r = [name rangeOfString:searchText options:NSCaseInsensitiveSearch];        
        if(r.location != NSNotFound)            
        {           
            if(r.location== 0)//that is we are checking only the start of the names.                
            {               
                [tableData addObject:name];             
            }           
        }       
        counter++;      
        [pool release];
    }
for(int i=0;i<[数据源计数];i++)
{
NSMutableDictionary*temp=(NSMutableDictionary*)[datasourceobjectatindex:i];
NSString*名称=[NSString stringWithFormat:@“%@,[temp valueForKey:@“名称”];
NSAutoreleasePool*池=[[NSAutoreleasePool alloc]init];
NSRange r=[名称范围字符串:搜索文本选项:NSCaseInsensitiveSearch];
if(r.location!=NSNotFound)
{           
if(r.location==0)//也就是说,我们只检查名称的开头。
{               
[tableData addObject:名称];
}           
}       
计数器++;
[池释放];
}

NSRange r=[名称范围字符串:搜索文本选项:NSCaseInsensitiveSearch];从数据源接收的值名称存储了什么?它存储了搜索的字符串值。如果数据源是字典,如何搜索?它应该是字典数组