-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
if (searchText.length == 0)
isActive = NO;
else
isActive = YES;
NSMutableArray *tmpSearched = [[NSMutableArray alloc] init];
NSMutableArray *tmpSearchedNumber = [[NSMutableArray alloc]init];
NSUInteger count1=0;
//NSUInteger count2=0;
for(count1=0;count1<[tableStationData count] || [tableData count];count1++)
{
NSRange range = [[tableStationData objectAtIndex:count1] rangeOfString:searchText options:NSCaseInsensitiveSearch];
NSRange range1= [[tableData objectAtIndex:count1]rangeOfString:searchText options:NSCaseInsensitiveSearch];
if(range.location !=NSNotFound || range1.location != NSNotFound)
{
[tmpSearchedNumber addObject:[tableStationData objectAtIndex:count1]];
[tmpSearched addObject:[tableData objectAtIndex:count1]];
}
}
其中tableData数组大小为:2530
和相同的数组大小tableStationData。当我在UISearchbar上搜索时,编码给出了错误。
最佳答案
我会改变这个
for(count1=0;count1<[tableStationData count] || [tableData count];count1++)
为了这
for(count1=0;count1<[tableStationData count] && count1<[tableData count];count1++)
编辑:用rmaddy的观测校正了最后一行。
如果
tableData
至少包含1个元素,则使用循环条件的方式将始终为true,并且循环将永远不会退出。