Code:
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
// remove all data that belongs to the previous search
[TtableData removeAllObjects];
[RtableData removeAllObjects];
[BtableData removeAllObjects];
if([searchText isEqualToString:@""] || searchText==nil) {
[myTable reloadData];
return;
}
NSString *searchLower = [searchText lowercaseString];
NSInteger counter = 0;
for(NSString *name in BdataSource) {
NSString *nameLower = [name lowercaseString];
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
NSRange r = [nameLower rangeOfString:searchLower];
if(r.location != NSNotFound) {
[RtableData addObject:[RdataSource objectAtIndex:counter]];
[TtableData addObject:[TdataSource objectAtIndex:counter]];
[BtableData addObject:[BdataSource objectAtIndex:counter]];
}
counter++;
[pool release];
}
[myTable reloadData];
}
This is the search method employed by my program. I used to have my program set up so that you had three windows. Navigation, search, and detail. Normally, you would make a selection in navigation and it would go straight to detail, but if you wanted to search, you would make a pit stop, and then load detail. With this structure, the search functioned smoothly on my test device.
When I merged search into navigation, and used a BOOL to have the navigation functions switch between normal and searching, the search still worked, but it had slowed down a lot. I keep getting 'sticky buttons' while I'm typing into the search bar.
It's the same code, but . . .
All the arrays were allocated, and initiated in ViewDidLoad. The DataSources were also populated there.
Does anybody know how I can streamline this search, and make it run smoothly again?