0

I am having a strange problem. When I add a record to entities i.e. core data from certain screens, the table view instead of showing the new record, repeats the previous record.

It always happens with some entities and screens, i.e. if I add records, 1,2,3 etc. it will display 1,1,1. With other screens and entities that use identical code, it sometimes happens, usually after about the eight through tenth record.

In these cases, if I add records named 1,2,3…10, it will display 1,2,3,4,5,6,7,8,8,8,8,8,8 etc.

Has anyone ever encountered this strange/spooky behavior? Why would it think that the new record is the same as the previous record either right away or at some point i.e. when the number of records hits 8 or so?

Note, it saves fine in core data as when I close the simulator and rebuild, it shows the right records.

The delegate pattern also seems to be working—somewhat—as it shows a new record when one is added, only it shows a copy of the last record and then the record on which it got stuck, i.e. 8,8,8 etc.

Thanks for any suggestions. This has been driving me crazy for a week now.

Am posting without code as SO will not accept the code I posted for some reason... Happy to post any code requested.

Edit:

#pragma mark - Table view data source

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"Cell"];

        Lists *list = [self.fetchedResultsController objectAtIndexPath:indexPath];

        cell.textLabel.text = list.listname;
        cell.detailTextLabel.text = list.list;

        return cell;
    }

In response to Duncan:

Apple's documentation states:

"A delegate must implement at least one of the change tracking delegate methods in order for change tracking to be enabled. Providing an empty implementation of controllerDidChangeContent: is sufficient."

My code includes:

#pragma mark - NSFetchedResultsControllerDelegate

-(void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
    //change
}

I know there is a more verbose method with will change content and did change content with a switch statement for different cases but the documentation says that is not necessary. (I also tried it and it did not fix problem.) I declare the list file as the delegate in the header with:

@interface ListsVC : UITableViewController<UITableViewDataSource, UITableViewDelegate,NSFetchedResultsControllerDelegate>
user1904273
  • 4,562
  • 11
  • 45
  • 96
  • Can you post the cellForRowAtIndexPath method? – Dario Mar 20 '15 at 18:56
  • 1
    Have you implemented the FetchedResultsController delegate methods correctly ?? Post the code for them. – Duncan Groenewald Mar 20 '15 at 23:14
  • I seem to have finally stumbled on a solution. It had to do with the sort descriptor sorting on a different attribute i.e. field than was being entered which apparently interferes with the delegate process. There is a debate about whether this is a bug. See answer by Jody Hagins here: http://stackoverflow.com/questions/12370521/changing-a-managed-object-property-doesnt-trigger-nsfetchedresultscontroller-to – user1904273 Mar 21 '15 at 15:11

1 Answers1

0

For me, it's a bug in the TableView. In fact, the last row is twice displayed but the "last" row is empty. I solved the problem by adding this code in my linked css (fill empty rows whit the same background and text-fill color and remove the borders. It works fine!

.table-row-cell:empty .table-cell 
-fx-border-width: 0px;
-fx-background-color: white;
-fx-text-fill: white;
A J
  • 3,970
  • 14
  • 38
  • 53