Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID

TableView UISearchBar Crashes while Searching

vksmainivksmaini Posts: 16Registered Users
edited September 2011 in iPhone SDK Development
I've been playing around with a search facility for my application table view for a while now trying to get it working but i keep getting the same error in my console.

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: ' [NSCFDictionary rangeOfString:options:]: unrecognized selector sent to instance

DataSource is an array which is taking itz value from a dictionary.... and tableData will be storing data that will be displayed in table.

Q: Suppose I have a dictionary with 5 values each having different keys corresponding to those values.. then i put that dictionary in an array. Can that array be used as a dataSource for search? and i am using the same array in cellForRowAtIndexPath to display data on my cells.

Plz suggest with code snippet.

Here is my code for 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]; 
    }
Sign In or Register to comment.