I have a problem updating my tableView. So, I know how to implement autocomplete textfield with tableView. The problem is that my keyboard typing is not as smooth as I want it to be. Flow goes like this: when I type 3 characters, my async server method is called. It's response object returns my searched addresses. But the problem is that when I type, for like half a second, I cannot do anything, I need to wait until it loads result. I was wondering to solve it with dispatch_group_t
but I need to enter and leave that async and then in notify method actually update my UI. This is the code:
if (string.length == 0 && range.length > 0) {
if (newText.length >= 3) {
dispatch_async(dispatch_get_main_queue(), ^{
[Address getAddreses:newText city:[City getDefaultCity] location:self.lockedPosition block:^(NSError *error, NSArray *addresses) {
self.suggestedAddresses = addresses;
if (addresses.count < AUTOCOMPLETE_RESULTS_MAX) {
self.sugesstedAddressesMaxResult = self.suggestedAddresses;
}
else {
self.sugesstedAddressesMaxResult = [addresses subarrayWithRange:NSMakeRange(0, AUTOCOMPLETE_RESULTS_MAX)];
}
[self calculateTableViewFrame:self.manualLocationInput tableViewTag:TAG];
[self.myTableView reloadData];
}];
});
}
}
What I want to do: type as fast as I can, not to wait on every character half a second to update my UI. Typing should be like typing in messages, but it needs to update my table view according to latest typing.