Hashem Aboonajmi
Hashem Aboonajmi

Reputation: 13830

updating NSManagedObject doesn't call NSFetchedResultsControllerDelegate using MagicalRecord

I have a model with this one to many relationShip:

Order -->> LineItem 

I display LineItems in UITableViewCells:

enter image description here

I use UIPickerView for changing quantity of LineItems.

GOAL=> by changing picker value, subTotal be recalculated again.

the problem is here by updating lineItem, NSFetchedResultsController Delegate doesn't call (where I can reconfigure the cell again and display updated data). but when I update Order e.g set it as completed NSFetchedResultsController Delegate methods will be called.

why by updating lineItem doesn't affect delegates methods to be called?

I use magicalRecord and here is how I get NSFetchedResultsController

- (NSFetchedResultsController *)fetchedResultsController
{
    if (_fetchedResultsController != nil) {
        return _fetchedResultsController;
    }
    else
    {
        _fetchedResultsController = [Order fetchAllSortedBy:@"orderDate" ascending:YES withPredicate:nil groupBy:nil delegate:self];
    }

    return _fetchedResultsController;
}

the way I setup table view:

ConfigureCellBlock configureCell = ^(OrderDetailsCell *cell, LineItem *lineItem)
{
    [cell configureForLineItem:lineItem];
};
//set fetchedresults controller delegate
Order *order = [[self.fetchedResultsController fetchedObjects] lastObject];
NSArray *lineItems = [order.lineItems allObjects];

self.ordersDataSource = [[ArrayDataSource alloc] initWithItems:lineItems cellIdentifier:@"lineItemCell" configureCellBlock:configureCell];
self.tableView.dataSource = self.ordersDataSource;

configuring cell:

- (void)configureForLineItem:(LineItem *)lineItem
{

self.menuItemName.text = lineItem.menuItemName;
self.price.text = [lineItem.unitPrice stringValue];
self.quantity.text = [lineItem.quantity stringValue];
self.totalPrice.text = [lineItem.totalPrice stringValue];

self.pickerController.model = lineItem;
self.picker.delegate = self.pickerController;
self.picker.dataSource = self.pickerController;
[self.picker setSelectedNumber:lineItem.quantity];
}

does fetching obj1 then updating obj3 cause the NSFRC delegate methods to be called?

enter image description here

Upvotes: 0

Views: 108

Answers (1)

Wain
Wain

Reputation: 119031

The FRC will only observe changes to the objects that it is directly interested in, not any of the objects that they are related to.

You should configure your own observation, either directly with KVO or to the context being saved, and use that to trigger a UI refresh.

Upvotes: 1

Related Questions