0

I need some help here. I got this error "NSInvalidArgumentException', reason: '-[__NSArrayM isEqualToString:]" when i tried to run my application. Anyone can identify the error i have? This is my codes...

- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar

{


sBar.showsCancelButton = YES;

sBar.autocorrectionType = UITextAutocorrectionTypeNo;

[tableData removeAllObjects];


myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 40, 320, 440)];
myTableView.delegate = self;
myTableView.dataSource = self;
[self.view addSubview:myTableView];
//initialize the two arrays; dataSource will be initialized and populated by appDelegate
searchedData = [[NSMutableArray alloc]init];
tableData = [[NSMutableArray alloc]init];

dataSource= [[NSMutableArray alloc]init];

Service *aService;
for(int i=0; i<[appDelegate.blocks count]; i++){
    aService = [appDelegate.blocks objectAtIndex:i];

    [dataSource addObject:[aService name]];


}
//dataSource = [dataSource sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];

//NSLog(@"%@",dataSource);


NSMutableArray *newSectionsArray = [[NSMutableArray alloc] initWithCapacity:26];// = [[NSMutableArray alloc] initWithCapacity:26];
for (int index = 0; index < 26; index++) {
    NSMutableArray *array = [[NSMutableArray alloc] init];
    [newSectionsArray addObject:array];

    [array release];
}



for(int i=0; i<[dataSource count]; i++){
    NSString *miscKey = @"#";
    NSString *try;
    NSString *Represent =[dataSource objectAtIndex:i];
    NSLog(@"%@",Represent);
    try=([Represent length] ==0)?miscKey:[[Represent substringToIndex:1]uppercaseString];

    if([try isEqualToString: @"A"]){
        NSLog(@"a");
        NSMutableArray *sectionTimeZones = [newSectionsArray objectAtIndex:1];
        [sectionTimeZones addObject:Represent];
        NSLog(@"a  %@",Represent);
    }
    else if([try isEqualToString: @"C"]){
        NSLog(@"c");
        NSMutableArray *sectionTimeZones = [newSectionsArray objectAtIndex:3];
        [sectionTimeZones addObject:Represent];
        NSLog(@"c  %@",Represent);

    }
    else if([try isEqualToString: @"D"]){
        NSLog(@"d");
        NSMutableArray *sectionTimeZones = [newSectionsArray objectAtIndex:4];
        [sectionTimeZones addObject:Represent];
        NSLog(@"d  %@",Represent);

    }
    else if([try isEqualToString: @"N"]){
        NSLog(@"n");
        NSMutableArray *sectionTimeZones = [newSectionsArray objectAtIndex:9];
        [sectionTimeZones addObject:Represent];
        NSLog(@"n  %@",Represent);

    }
    else if([try isEqualToString: @"O"]){
        NSLog(@"o");
        NSMutableArray *sectionTimeZones = [newSectionsArray objectAtIndex:10];
        [sectionTimeZones addObject:Represent];
        NSLog(@"o  %@",Represent);          
    }
    else if([try isEqualToString: @"P"]){
        NSLog(@"p");
        NSMutableArray *sectionTimeZones = [newSectionsArray objectAtIndex:11];
        [sectionTimeZones addObject:Represent];
        NSLog(@"p  %@",Represent);

    }
    else if([try isEqualToString: @"S"]){
        NSLog(@"s");
        NSMutableArray *sectionTimeZones = [newSectionsArray objectAtIndex:14];
        [sectionTimeZones addObject:Represent];
        NSLog(@"s  %@",sectionTimeZones);           
    }
    else if([try isEqualToString: @"T"]){
        NSLog(@"t");
        NSMutableArray *sectionTimeZones = [newSectionsArray objectAtIndex:15];
        [sectionTimeZones addObject:Represent];
        NSLog(@"t  %@",Represent);          
    }
    else{}



}   

//NSLog(@"%@",newSectionsArray);
[tableData addObjectsFromArray:newSectionsArray];

    //[tableData addObjectsFromArray:dataSource];

}
robobooga
  • 513
  • 6
  • 19
  • What line of code generates this exception? To do this, add a breakpoint on objc_exception_thrown [tutorial here](http://stackoverflow.com/questions/1163981/how-to-add-a-breakpoint-to-objc-exception-throw). Run the application and after it crashes open the debugger window. There you should find the current stack trace you should be able to see what was the line of code that generated the exception. – Andrei Stanescu Feb 17 '11 at 15:42

1 Answers1

0

It might have to do with the use of "try" as variable. Try to rename it to something else and give it a go!

Qiau
  • 5,976
  • 3
  • 29
  • 40