uitableview - Search bar in core data project -
i use core data magical record , i'm try filter data search bar in table view.
i write 2 methods number of rows , name of cells:
-(int) damminumerocercati:(nsstring *)searchbar { nspredicate *predicate = [nspredicate predicatewithformat:@"nome contains [cd] %@", searchbar]; nsarray*arra = [ricetta mr_findallsortedby:@"nome" ascending:yes withpredicate:predicate]; return arra.count; } -(nsstring*) damminomericettacercata:(nsstring *)searchbar mostratanellacella: (int) cella { nspredicate *predicate = [nspredicate predicatewithformat:@"nome contains [cd] %@", searchbar]; nsarray *arra = [ricetta mr_findallsortedby:@"nome" ascending:yes withpredicate:predicate]; ricetta*ctn = arra[cella]; return [nsstring stringwithformat:@"%@", ctn.nome]; }
then call method inside numberofrowsinsection: , cellforrowatindexpath: inside if cycle:
if (self.mysearchbar.isfirstresponder){ // above methods } else { // normals methods have data }
somebody know i'm wrong or if miss somethings?
searchbar
uisearchbar
, not string.
you should use searchbar.text
, process in methods.
also, in table view's datasource methods have make sure table view causing callback, , return correct count/string. checked comparing pointers 2 tables (original table view , search results table view).
-(nsuinteger)tableview:(uitableview*)tableview numberofrowsinsection:(nsuinteger)section { if (tableview == _tableview) { // return usual row count } return [self damminumerocercati:_searchbar.text]; }
Comments
Post a Comment