我正在我的 NSMutableArray 中进行某种搜索,但我经常得到 SIGABRT。我是objective-c的新手,所以我不知道我是否错过了一些重要的东西......
-(IBAction)findButtonPushed:(id)sender
{
Data *stuff = [Data getInstance];
[stuff.results removeAllObjects];
NSMutableArray *tempResults = [[NSMutableArray alloc] init];
for (Company *company in stuff.companies) {
if ([company.Description rangeOfString:[sbWhat text] options:NSCaseInsensitiveSearch].location != NSNotFound
|| [company.Name rangeOfString:[sbWhat text] options:NSCaseInsensitiveSearch].location != NSNotFound
|| [company.Url rangeOfString:[sbWhat text] options:NSCaseInsensitiveSearch].location != NSNotFound
|| [company.FirstName rangeOfString:[sbWhat text] options:NSCaseInsensitiveSearch].location != NSNotFound
|| [company.LastName rangeOfString:[sbWhat text] options:NSCaseInsensitiveSearch].location != NSNotFound
|| [company.Keywords rangeOfString:[sbWhat text] options:NSCaseInsensitiveSearch].location != NSNotFound) {
[tempResults addObject:company];
}
}
if (![[sbWhere text] isEqualToString:@""]) {
for (Company *company in tempResults) {
if ([company.Street rangeOfString:[sbWhere text] options:NSCaseInsensitiveSearch].location != NSNotFound
|| [company.City rangeOfString:[sbWhere text] options:NSCaseInsensitiveSearch].location != NSNotFound
|| [company.ZipCode rangeOfString:[sbWhere text] options:NSCaseInsensitiveSearch].location != NSNotFound
|| [company.State rangeOfString:[sbWhere text] options:NSCaseInsensitiveSearch].location != NSNotFound
|| [company.AddressPt1 rangeOfString:[sbWhere text] options:NSCaseInsensitiveSearch].location != NSNotFound
|| [company.AddressPt2 rangeOfString:[sbWhere text] options:NSCaseInsensitiveSearch].location != NSNotFound
|| [company.Country rangeOfString:[sbWhere text] options:NSCaseInsensitiveSearch].location != NSNotFound) {
[stuff.results addObject:company];
}
}
}
else{
stuff.results = tempResults;
}
[self performSegueWithIdentifier:@"ShowResults" sender:self];
}
顺便说一句,sbWhere 和 sb什么是 UISearchBars
我在这两个 if 语句上得到了 SIGABRT。我通过解析 json 字符串得到的公司。