How to throttle search (based on typing speed) in iOS UISearchBar? -
i have uisearchbar part of uisearchdisplaycontroller used display search results both local coredata , remote api. want accomplish "delaying" of search on remote api. currently, each character typed user, request sent. if user types particularly fast, not create sense send many requests: help wait until has stopped typing. there way accomplish that?
reading documentation suggests wait until users explicitly taps on search, don't find ideal in case.
performance issues. if search operations can carried out rapidly, possible update search results user typing implementing searchbar:textdidchange: method on delegate object. however, if search operation takes more time, should wait until user taps search button before origin search in searchbarsearchbuttonclicked: method. perform search operations background thread avoid blocking main thread. keeps app responsive user while search running , provides improve user experience.
sending many requests api not problem of local performance of avoiding high request rate on remote server.
thanks
try magic:
-(void)searchbar:(uisearchbar *)searchbar textdidchange:(nsstring *)searchtext{ // limit network activity, reload half sec after lastly key press. [nsobject cancelpreviousperformrequestswithtarget:self selector:@selector(reload) object:nil]; [self performselector:@selector(reload) withobject:nil afterdelay:0.5]; }
ios search
No comments:
Post a Comment