ios - Autocomplete UITextField Async update UITableView -


i have problem updating tableview. so, know how implement autocomplete textfield tableview. problem keyboard typing not smooth want be. flow goes this: when type 3 characters, async server method called. it's response object returns searched addresses. problem when type, half second, cannot anything, need wait until loads result. wondering solve dispatch_group_t need enter , leave async , in notify method update ui. 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 want do: type fast can, not wait on every character half second update ui. typing should typing in messages, needs update table view according latest typing.

if observe code fetch results of web service happening in displath_main-queue. why facing issues while typing keyboard. move dispatch_get_main_queue block next level shown below. should problem.

     //dispatch_queue_t myqueue = dispatch_queue_create("my queue",null);      dispatch_queue_t globalconcurrentqueue =      dispatch_get_global_queue(dispatch_queue_priority_default, 0)     dispatch_async(globalconcurrentqueue, ^{      if (string.length == 0 && range.length > 0) {     if (newtext.length >= 3) {             [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)];                 }                 dispatch_async(dispatch_get_main_queue(), ^{                 [self calculatetableviewframe:self.manuallocationinput tableviewtag:tag];                 [self.mytableview reloaddata];             }];         });      }   } } 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -