0
我需要一些幫助。我得到這個錯誤「NSInvalidArgumentException」,原因:' - [__ NSArrayM isEqualToString:]「當我試圖運行我的應用程序。任何人都可以識別我的錯誤? 這是我的代碼...Xcode 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];
}
哪行代碼會產生此異常?爲此,請在objc_exception_thrown [tutorial here]上添加一個斷點(http://stackoverflow.com/questions/1163981/how-to-add-a-breakpoint-to-objc-exception-throw)。運行應用程序並在崩潰後打開調試器窗口。在那裏你應該找到當前堆棧跟蹤,你應該能夠看到生成異常的代碼行是什麼。 – 2011-02-17 15:42:58