I have an app that allows searches of an sql db by various fields (name, city, id) I have tried to implement the searches as NSOperations in a queue. and the ui is updated between the first search but for some reason the tableview will not respond to touches while the operations are continuing in the background. Not sure what i’ve missed or if i need a custom runloop for the operation queue if so would appreciate some help with that as i’m not familiar enough with that here’s my existing code
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
NSString *searchText = searchBar.text;
[self.searchQueue cancelAllOperations]; //NSOperationQueue
[self.searchResults startSearching:searchText];
[self searchID:searchText];
NSInvocationOperation *operation1 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(searchName:) object:searchText];
[self.searchQueue addOperation:operation1];
[operation1 release];
//NSLog(@"Add city search");
NSInvocationOperation *operation2 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(searchCity:) object:searchText];
[self.searchQueue addOperation:operation2];
[operation2 release];
}
so what happens is the UI is held until the first search ends (that’s ok) and it refreshes the table view. As as each operation completes it refreshes the tableview, however during this time the tableview will not respond to touches…
the task itself looks like this..
-(void) searchCity:(NSString *)City{
searchObject *myCity = [[searchObject alloc] init];
self.searchResults.cityResults = [myCity searchCity:City]; //returns NSArray of items
if ([self.searchResults.cityResults count] == 0) {
[self.searchResults.cityResults addObject:[NSArray arrayWithObjects:@"Not Found.",@"",@"",@"",@"", nil]];
}
[self.searchResults refreshView];
//NSLog(@"Added from City Search\n%@",self.searchResults.cityResults);
}
OK i answered my own question but for the next folks…
it was as simple as ensuring that the tableview refresh was performed on the main thread…