I've added a search bar to my project and it works quite well. You can search for object (of a table view) and the relations also work. But the search display doesn't show the result names.
For example: I have no object which begins with "x" >>> So no result (That's correct):
But one object starts with "b", but the name isn't displayed although I can click on it and it shows me the next view (Relation) correctly:
Maybe this is caused due to my code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *simpleTableIdentifier = @"CarCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
if (tableView == self.searchDisplayController.searchResultsTableView) {
Car *search = [searchResults objectAtIndex:indexPath.row];
UILabel *carNameLabel = (UILabel *)[cell viewWithTag:101];
carNameLabel.text = search.name;
I don't know why this doesn't work and this seems to be very strange to me. It would be great if someone can help me.
Update: Full method
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *simpleTableIdentifier = @"CarCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
if (tableView == self.searchDisplayController.searchResultsTableView) {
Car *search = [searchResults objectAtIndex:indexPath.row];
UILabel *carNameLabel = (UILabel *)[cell viewWithTag:101];
carNameLabel.text = search.name;
} else {
Car *car = [cars objectAtIndex:indexPath.row];
UIImageView *carImageView = (UIImageView *)[cell viewWithTag:100];
carImageView.image = [UIImage imageNamed:car.thumbnail];
UILabel *carNameLabel = (UILabel *)[cell viewWithTag:101];
carNameLabel.text = car.name;
UILabel *carSpeedLabel = (UILabel *)[cell viewWithTag:102];
carSpeedLabel.text = car.carSpeed;
}
return cell;
}