ios - UISearchDisplay crashes because of key value -


i have working table view controller populates based on xml files corresponding previous table view controller. works fine until tried adding uisearchdisplaycontroller.

after going through tutorials tried implementing code app keeps crashing below error:

** terminating app due uncaught exception 'nsunknownkeyexception', reason: '[<__nscfstring 0x175949e0> valueforundefinedkey:]: class not key value coding-compliant key name.' **

here relevant code snippets .m file:

- (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section {     if (tableview == self.searchdisplaycontroller.searchresultstableview) {         return self.searchresults.count;     } else {         return _refs.subreference.count;     }       }  - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     subrefcell *cell = [self.tableview dequeuereusablecellwithidentifier:@"tablecell"forindexpath:indexpath];      if (cell == nil) {         nslog(@"error nil cell");     }      int row=[indexpath row];      if (tableview == self.searchdisplaycontroller.searchresultstableview) {          cell.subreflabel.text = self.searchresults[row];         cell.subrefdesclabel.text = _refs.subrefdesc[row]; //fix later      } else {         //set cells sub reference names , descriptions         cell.subreflabel.text = _refs.subreference[row];         cell.subrefdesclabel.text = _refs.subrefdesc[row];     }     return cell; }  #pragma search methods  - (void)filtercontentforsearchtext:(nsstring*)searchtext scope:(nsstring*)scope {     nspredicate *resultpredicate = [nspredicate predicatewithformat:@"name contains[c] %@", searchtext];     //self.searchsubref = _refs.subreference;     nslog(@"here list of refs %@",_refs.subreference);      //crashes right after line     self.searchresults = [_refs.subreference filteredarrayusingpredicate:resultpredicate];     nslog(@"test");         }  -(bool)searchdisplaycontroller:(uisearchdisplaycontroller *)controller shouldreloadtableforsearchstring:(nsstring *)searchstring {            [self filtercontentforsearchtext:searchstring                                scope:[[self.searchdisplaycontroller.searchbar scopebuttontitles]                                       objectatindex:[self.searchdisplaycontroller.searchbar                                                      selectedscopebuttonindex]]];            return yes; } 

i have custom cells , checked '!' on outlets both tableview controller , table view cell seemed ok. tried open storyboard source code , outlets called 'name' no luck.

any ideas going wrong , why app crashes try typing search bar?

the problem appeared missing uitableviewcell initialiser statement. dequeuing tableview cell without creating in first place.

you need following statement if dequeue returns nil,

 if (cell == nil) {     cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:@"tablecell"];  } 

what if dequeuereusablecellwithidentifier returns nil, creating one?

besides using different variants of initialiser needs register class or nib file using registernib:forcellreuseidentifier: or registerclass:forcellreuseidentifier: method before calling following method,

 [tableview dequeuereusablecellwithidentifier:@"tablecell" forindexpath:indexpath] 

register nib in viewdidload follows

uinib *cellnib = [uinib nibwithnibname:@"subrefcell" bundle:nil]; [mytable registernib:cellnib forcellreuseidentifier:@"tablecell"]; 

Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -