objective c - Is it possible to change predicates from a UIButton? -


i have set of words in core data model. have buttons filter based on category, adjectives, verbs, etc.

i have code below, table not reload..

> - (ibaction)selectadjectives:(id)sender { >     nslog(@"%s", __function__); >     predicateswitch = 3; // int >     [nsfetchedresultscontroller deletecachewithname:nil]; >     [self.wordtable reloaddata]; } >    > - (nspredicate*)predicate { >     nslog(@"%s", __function__); >     nspredicate *predicate = [[nspredicate alloc] init]; >     switch (predicateswitch) { >         case 0: >             predicate = nil; >             break; >          >         case 1: >             ... >             break; >              >         case2: >             ... >              >         case3: >             predicate = [nspredicate predicatewithformat:@"self.category contains[c] %@",@"adjective"]; >             break; >              >  >         default: >             predicate = [nspredicate predicatewithformat:@"self.category contains[c] %@",@"noun"]; >             break; >     } >     nslog(@"predicate: %@", predicate); >      >     return predicate; } >    > - (nsfetchedresultscontroller *)fetchedresultscontroller { >     //nslog(@"%s", __function__); >      >     if (_fetchedresultscontroller != nil) { >         return _fetchedresultscontroller; >     } >      >     nsfetchrequest *fetchrequest = [[nsfetchrequest alloc] init]; >      >     nsentitydescription *entity = [nsentitydescription entityforname:@"wordentity" > inmanagedobjectcontext:self.managedobjectcontext]; >     [fetchrequest setentity:entity]; >     [fetchrequest setpredicate:[self predicate]]; >           // create sort descriptors array.    ... >       >     nsarray *sortdescriptors = @[sortdescriptor]; >     [fetchrequest setsortdescriptors:sortdescriptors]; >      >     // create , initialize fetch results controller. >     _fetchedresultscontroller = [[nsfetchedresultscontroller alloc] initwithfetchrequest:fetchrequest > managedobjectcontext:self.managedobjectcontext sectionnamekeypath:nil > cachename:nil]; >      >     _fetchedresultscontroller.delegate = self; >      >     return _fetchedresultscontroller; }   - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     //nslog(@"%s", __function__);      static nsstring *cellidentifier = @"wordcell";      uitableviewcell *cell = (uitableviewcell *)[self.wordtable dequeuereusablecellwithidentifier:cellidentifier];      // configure cell...     if (cell == nil) {         cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstylesubtitle reuseidentifier:cellidentifier];     }      wordentity *word = nil;     if (tableview == self.searchdisplaycontroller.searchresultstableview) {         word = [self.searchresults objectatindex:indexpath.row];         count = self.searchresults.count;         self.numberwordslabel.text = [nsstring stringwithformat:@"%lu", (unsigned long)count];      } else {         word = [self.fetchedresultscontroller objectatindexpath:indexpath];         self.numberwordslabel.text = [nsstring stringwithformat:@"%lu", (unsigned long)fullcount];     }           cell.textlabel.text =  .....;         cell.detailtextlabel.text = .....; 

i whole table, predicates not firing, , table view not reloaded. i'd appreciate advice.

several things wrong..

  1. see switch statement. there missing space in cases 2 , 3.

  2. you can't reload table. have reload view controller.. (i don't i'm open alternatives).

  3. you can't reset cache with

    [nsfetchedresultscontroller deletecachewithname:nil];

you have hammer it:

self.fetchedresultscontroller = nil; 

so:

- (ibaction)selectnouns:(id)sender {     //nslog(@"%s", __function__);     predicateswitch = 1;     self.fetchedresultscontroller = nil;      [self viewdidload]; } 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

python - Django-cities exits with "killed" -

python - How to get a widget position inside it's layout in Kivy? -