ios - NSPredicate keeps crashing my app -
i've created searchbar thats suppose filter uitableview have setup. i'm using parse.com pull array down app.
- (void)viewdidload { [super viewdidload]; // additional setup after loading view. [self query]; //[self.searchdisplaycontroller.searchresultstableview registernib:[uinib nibwithnibname:@"searchcell" bundle:nil] forcellreuseidentifier:@"searchdata"]; } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } -(void)query { pfquery *q = [pfquery querywithclassname:@"_user"]; [q selectkeys:@[@"username"]]; [q findobjectsinbackgroundwithblock:^(nsarray *objects, nserror *error) { if (!error) { nslog(@"load array); searharray = [[nsarray alloc] initwitharray:objects]; } else{ nslog(@"array no good"); } }]; }
then attempt filter array using these lines of code
-(void)searchbar:(uisearchbar *)searchbar textdidchange:(nsstring *)searchtext { self.searchterm = searchtext; } -(void)searchbarcancelbuttonclicked:(uisearchbar *)searchbar { [self.mysearchbar resignfirstresponder]; //reset original array , reload table self.filteredcities = searharray; [self.mytableview reloaddata]; } -(void)searchbarsearchbuttonclicked:(uisearchbar *)searchbar { [self.mysearchbar resignfirstresponder]; if ([self.searchterm isequaltostring:@""]) { // nothing here - reset original array , reload table self.filteredcities = searharray; } else { // filter array based on term searched using predicate nspredicate *predicate = [nspredicate predicatewithformat:@"self.title contains[c] %@",self.searchterm]; self.filteredcities = [nsarray arraywitharray:[searharray filteredarrayusingpredicate:predicate]]; } [self.mytableview reloaddata]; } -(void)searchbartextdidbeginediting:(uisearchbar *)searchbar { self.filteredcities = searharray; [self.mytableview reloaddata]; }
but keeps crashing. i've debugged problem down line
self.filteredcities = [nsarray arraywitharray:[searharray filteredarrayusingpredicate:predicate]];
the error is:
`2015-03-31 19:31:19.783 pondu[59307:5149459] *** terminating app due uncaught exception 'nsinternalinconsistencyexception', reason: 'key "words" has no data. call fetchifneeded before getting value.' *** first throw call stack: (0x18724a59c 0x1979a00e4 0x18724a4dc 0x1000c34bc 0x1880350f0 0x18807b934 0x18807b394 0x18807a084 0x188079e58 0x1000b31b0 0x18be207ac 0x18ba30d34 0x18ba19e48 0x18bbf91dc 0x18bbc3f04 0x18bd80890 0x18bd80540 0x18ba24950 0x18811ddf0 0x1872029ec 0x187201c90 0x1871ffd40 0x18712d0a4 0x1902cf5a4 0x18ba623c0 0x1000b1f64 0x19800ea08) libc++abi.dylib: terminating uncaught exception of type nsexception`
self.searchterm seems nsstring put there supposing value nsdictionary. need use
@"self matches %@"
, not
@"self.title matches %@"
Comments
Post a Comment