Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__NSCFString 0x9c7aaf0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key name
I searched stackoverflow.com for a solution to this error but I didn't find any. I think I might have a different problem.
I'm trying to implement UISearchdisplaycontroller in my project. I have a UITableview displaying content from a sqlite database and after displaying I want to perform a search. I'm unable to do so. please someone help.
Here is my code:
-(void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"name contains[c] %@", searchText];
searchResults = [jobTitleArray filteredArrayUsingPredicate:resultPredicate];`
}
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
[self filterContentForSearchText:searchString scope:
[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];
return YES;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//int rowCount;
if (tableView == self.searchDisplayController.searchResultsTableView)
{
NSLog(@"Search count %d",[searchResults count]);
return [searchResults count];
} else
{
NSLog(@"jobTitleArray Search count %d",[jobTitleArray count]);
return [jobTitleArray count];
}
//return rowCount;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
JobDetailViewController *jobD = [[JobDetailViewController alloc] init];`
NSLog(@"Before: %@", jobD);
if (tableView == self.searchDisplayController.searchResultsTableView) {
[self performSegueWithIdentifier: @"showJobDetail" sender: self];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath`
{
static NSString *CellIdentifier = @"Cell";
//jobTableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
jobTableCell *cell = (jobTableCell *)[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];`
if (cell == nil) {
cell = [[jobTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
JobDone *jobD = nil;
if (tableView == self.searchDisplayController.searchResultsTableView) {
NSLog(@"job %@",searchResults);
jobD = [searchResults objectAtIndex:indexPath.row];
} else
{
jobD = [jobTitleArray objectAtIndex:indexPath.row];
}
cell.companyLabel.text=[companyArray objectAtIndex:indexPath.row];
cell.titleLabel.text = [jobTitleArray objectAtIndex:indexPath.row];
cell.descLabel.text=[descArray objectAtIndex:indexPath.row];
return cell;
}