ios - Display of results is delayed by 5s in UISearchDisplayController -
my uisearchdisplaycontroller performs asynchronous searches via nsoperationqueue.
however results table not visually update until approximately 5s after nsoperation calls [searchdisplaycontroller.searchresultstableview reloaddata].
- (bool) searchdisplaycontroller:(uisearchdisplaycontroller*)controller shouldreloadtableforsearchstring:(nsstring*)searchstring { [searchqueue cancelalloperations]; nsinvocationoperation *op = [[[customsearchoperation alloc] initwithcontroller:controller searchterm:searchstring] autorelease]; [searchqueue addoperation:op]; return no; } my customersearchoperation updates tableview so:
- (void) main { // perform search [searchdisplaycontroller setcontents:results]; [searchdisplaycontroller.searchresultstableview reloaddata]; }
the problem ui updates must occur on main thread, , reloaddata being called background thread via nsoperationqueue.
you can use nsobject method performselectoronmainthread:withobject:waituntildone: ensure such updates occur on main thread.
- (void) main { // perform search [sdc setcontents:results]; [sdc.searchresultstableview performselectoronmainthread:@selector(reloaddata) withobject:nil waituntildone:no]; }
Comments
Post a Comment