我需要一些帮助。当我试图运行我的应用程序时,我收到此错误“NSInvalidArgumentException”,原因:' - [__ NSArrayM isEqualToString:]“。任何人都可以识别我的错误? 这是我的代码......
- (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];
}
答案 0 :(得分:0)
它可能与使用“try”作为变量有关。 尝试将其重命名为其他内容并开始使用!