views:

58

answers:

2

Hello Everybody,

it seems my Problem isn't a problem for anybody eles because I havend fount anything about it. so it maybe isn't such a big Problem but for me it is.

I have this MutableArray filled with alot of data from an XML file. -Name -Age -Address The search goes for the Name, and the filtering works pretty fine so far.

what I do is search the array with rangeOfString but that only returns the String (-Name) and not the Array with it's content like the original Array because its only a string now.

can anyone tell me how do I accomplish this

That's my search so far

if ([[self searcher] length] != 0)
{
    for (NSString *currentString in [self listOfContent])
    {
        if ([currentString rangeOfString:searchTerm options:NSCaseInsensitiveSearch].location != NSNotFound)
        {
            [[self filteredListOfContent] addObject:currentString];
        }

searcher is the String in the SearchBar. or is there any other more efficent way or is it possible to search for any value in the MutipleArry?!?

Any Ideas and suggestions are welcome

I changed the code to this

NSString *searchText = searchBar.text;
NSMutableArray *searchArray = [[NSMutableArray alloc] init];

for (NSDictionary *dictionary in listOfContent)
{
    //NSArray *array = [dictionary objectForKey:LNAME];
    [searchArray addObject:dictionary];

}

for (NSString *sTemp in searchArray)
{
    NSLog(@"array %@", searchArray);

    if ([sTemp rangeOfString:searchText options:NSCaseInsensitiveSearch].location != NSNotFound)

        [filteredListOfContent addObject:searchArray];
}

the log shows that the filter seems to work but then I get this error

2010-10-22 16:18:09.708 TableView[6114:207] -[__NSCFDictionary rangeOfString:options:]: unrecognized selector sent to instance 0x5c3f540
2010-10-22 16:18:09.712 TableView[6114:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary rangeOfString:options:]: unrecognized selector sent to instance 0x5c3f540'

can anyone tell me what the problem is

And Still no solution found I changed the Code to this:

NSMutableArray *searchArray = [[NSMutableArray alloc] init];

        for (NSDictionary *dictionary in contentsList)
        {
            NSArray *array = [dictionary allValues];
            [searchArray addObjectsFromArray:array];
        }
        for (NSDictionary *dict in searchArray)
        {
            if ([[dict valueForKey:@"NAME"] rangeOfString:searchTerm options:NSCaseInsensitiveSearch].location != NSNotFound) {
                NSLog(@"Filter %@", dict);
                [searchResults addObject:dict];
            }

now i Have the array with the values but still get the error

2010-10-28 16:23:46.124 TableViews[8373:207] *** Terminating app due to uncaught exception 
'NSInvalidArgumentException', reason: '-[NSCFString objectForKey:]: unrecognized selector sent to instance 0x5a5eb00'

can anyone explain me waht taht that error means or waht I did wrong?!?

A: 
2010-10-28 16:23:46.124 TableViews[8373:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString objectForKey:]: unrecognized selector sent to instance 0x5a5eb00'

That error means you treated an NSString as if it were an NSDictionary by sending the message -objectForKey: to it.

Jeremy W. Sherman