Reputation: 509
I am attempting to create a Parent-Child Core Data relationship. TableViewA
contains car manufacturers and TableViewB
contains cars made by the selected manufacturer. I want to filter the cars so that they will only show up in their manufacturers table view. I have this working fairly well, but when I add a car in one manufacturers table view, it shows up correctly in the manufacturers table view in which it was added, but in all of the other manufacturers table views the cells only display their default label ("cell") for the number of cars added in other manufacturers table views. This is my tableView:cellForRowAtIndexPath:
method for TableViewB
:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Car Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
Car *car = [self.fetchedResultsController objectAtIndexPath:indexPath];
if (car.manufacturer == self.currentManufacturer) {
cell.textLabel.text = car.carName;
}
return cell;
}
Please explain how to properly filter in Core Data.
Upvotes: 0
Views: 372
Reputation: 5156
You need to modify the predicate assigned to your fetched results controller as the manufacturer is selected.
Upvotes: 1