ios - why nspredicate not working -


- (nsfetchedresultscontroller *)fetchedresultscontroller {     if (_fetchedresultscontroller != nil) {         return _fetchedresultscontroller;     }      nsfetchrequest *fetchrequest = [[nsfetchrequest alloc] init];      nsentitydescription *entity = [nsentitydescription entityforname:@"keyrefentity" inmanagedobjectcontext:self.managedobjectcontext];     [fetchrequest setentity:entity];      [fetchrequest setfetchbatchsize:20];      nssortdescriptor *sortdescriptor = [[nssortdescriptor alloc] initwithkey:@"time" ascending:no];     nsarray *sortdescriptors = @[sortdescriptor];      [fetchrequest setsortdescriptors:sortdescriptors];      nsfetchedresultscontroller *afetchedresultscontroller = [[nsfetchedresultscontroller alloc] initwithfetchrequest:fetchrequest managedobjectcontext:self.managedobjectcontext sectionnamekeypath:@"time" cachename:@"master"];     afetchedresultscontroller.delegate = self;     self.fetchedresultscontroller = afetchedresultscontroller;      nserror *error = nil;     if (![self.fetchedresultscontroller performfetch:&error]) {          nslog(@"unresolved error %@, %@", error, [error userinfo]);         abort();     }      return _fetchedresultscontroller; } 

- (void) searchbarsearchbuttonclicked:(uisearchbar *)thesearchbar {     if (self.searchbar.text !=nil)     {         nspredicate *predicate =[nspredicate predicatewithformat:@"ref contains[cd] %@", self.searchbar.text];         [self.fetchedresultscontroller.fetchrequest setpredicate:predicate];     }     else     {         nspredicate *predicate =[nspredicate predicatewithformat:@"all"];         [self.fetchedresultscontroller.fetchrequest setpredicate:predicate];     }      nserror *error = nil;     if (![[self fetchedresultscontroller] performfetch:&error])     {         nslog(@"unresolved error %@, %@", error, [error userinfo]);         exit(-1);     }      [self.searchbar resignfirstresponder];      [self.tableview reloaddata]; } 

i trying search using code, code inside searchbarsearchbuttonclicked: not working place break point code executes nothing happens.

not sure [nspredicate predicatewithformat:@"all"]; supposed it's unlikely work. when search text changes should replace fetch request , add new fetch request frc. frc docs:

initwithfetchrequest:managedobjectcontext:sectionnamekeypath:cachename:

important: must not modify fetchrequest after invoking method. example, must not change predicate or sort orderings.

your other problem frc using cache. changing fetch request when using cache not supported. general recommendation not use cache. if have use cache reason when (before) change fetch request need delete old cache - deletecachewithname:).

see docs frcs here.


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -