由于未捕获的异常终止应用程序&#39; NSUnknownKeyException&#39;,原因:&#39; [<restarauntentity 0x7ae3f080 =“”> valueForUndefinedKey:]

时间:2015-06-21 05:10:25

标签: ios uisearchbar sigabrt

我已使用下面列出的代码在uitableview中实现了搜索栏(和显示控制器)。当我在搜索文本框中输入时,我收到以下sigabrt错误:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<RestarauntEntity 0x7ae3f080> valueForUndefinedKey:]: this class is not key value coding-compliant for the key name.&#39;

我已经重新审核了我一直关注的教程并对代码进行了四倍检查,但是我找不到错误的原因,有人可以帮忙吗?

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView == self.searchDisplayController.searchResultsTableView) {
        return [self.searchResults count];
    } else {
        return _restaurantsInCity.count;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"RestaurantCell";
    UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }

    RestarauntEntity *currentRestaurant = nil;
    if (tableView == self.searchDisplayController.searchResultsTableView) {
        currentRestaurant = [[self.searchResults objectAtIndex:indexPath.row]];
    } else {
        currentRestaurant = [self.restaurantsInCity objectAtIndex:indexPath.row];
    }

    NSString *decodedText1 = [currentRestaurant.title stringByReplacingOccurrencesOfString:@"&#8217;" withString:@"'"];
    NSString *decodedText = [decodedText1 stringByReplacingOccurrencesOfString:@"&#038;" withString:@"&"];
    cell.textLabel.text = decodedText;
    cell.textLabel.font = [UIFont fontWithName:@"avenir" size:16.0f];
    cell.textLabel.textColor=[UIColor blackColor];
    cell.detailTextLabel.text = currentRestaurant.city;
    cell.detailTextLabel.font = [UIFont fontWithName:@"avenir" size:12.0f];
    cell.detailTextLabel.textColor=[UIColor darkGrayColor];

    return cell;
}

- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
    NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"name contains[cd] %@", searchText];
    searchResults = [_restaurantsInCity filteredArrayUsingPredicate:resultPredicate];
}

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
    [self filterContentForSearchText:searchString
                               scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
                                      objectAtIndex:[self.searchDisplayController.searchBar
                                                     selectedScopeButtonIndex]]];

    return YES;
}

0 个答案:

没有答案