2011-02-17 97 views
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]; 

} 
+0

哪行代码会产生此异常?为此,请在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

回答

0

这可能与使用的“试”为变量做。 尝试将其重命名为其他内容并给它一个!

相关问题