Note that there are some explanatory texts on larger screens.

plurals
  1. POUITableViewCell does not reflect changes after dismissing a modally presented ViewController
    text
    copied!<p>I have a UIViewController with a TableView for displaying the 'checklist' items. This ViewController also has a button that trigger the segue to modally present another UIViewController that is for users to add the new checklist items.</p> <p>All checklist items are stored in CoreData. </p> <p>The new CoreData entity is created, and stored by the <code>SecondViewController</code>. Users can add as much <code>checklist</code> items as they want before hitting a button that triggers the dismissal of the <code>SecondViewController</code>. Here since this <code>SecondViewController</code> is modally presented, I assume that its activity does not have any relation with the <code>FirstUIViewController</code> at all.</p> <p>At the <code>FirstViewController</code>, which contains <code>UITableView</code>, there is a <code>NSFetchedResultsController</code> that performs the fetch request at the CoreData again and feed all the data to <code>UITableView</code>. NSFetchedResultsController's delegate is also point to this <code>FirstUIViewController</code>.</p> <p>The problem is that, after the dismissal of <code>SecondViewController</code>, the <code>UITableView</code> seems to notice the insertion of the new checklist entity, and inserted the new <code>UITableCell</code> inside the UITableView. However, weirdly, this newly inserted row doesn't display the proper <code>cell.textlabel</code>. Only blank <code>UITableViewCell</code> with nothing on the label is presented.</p> <p>Below is how I configure the <code>UITableViewCell</code>.</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"ChecklistCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; [self configureCell:cell atIndexPath:indexPath]; return cell; } - (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath { ChecklistItem *item = [self.fetch_controller objectAtIndexPath:indexPath]; cell.textLabel.text = item.name; } </code></pre> <p>Here is what I have for the NSFetchedResultsControllerDelegate</p> <pre><code>- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath { switch (type) { case NSFetchedResultsChangeInsert: NSLog(@"*** controllerDidChangeObject - NSFetchedResultsChangeInsert"); [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade]; break; } } </code></pre> <p>Forcing the <code>[self.tableView reloadData]</code> seems to help. I know this because I added one button to invoke this method, and the cell's label got refreshed and updated accordingly.</p> <p>Therefore, I tried this as I hope it would get called after the dismissal of <code>SecondViewController</code>. However, the method gets called because <code>Reload Data!</code> got logged, but somehow the tableView still doesn't show the newly added cell's label properly.</p> <pre><code>- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self performFetch]; [self.tableView reloadData]; NSLog(@"Reload Data!"); } </code></pre> <p>I wonder what could be wrong here. Somehow the <code>self.tableView</code> doesn't get reloaded after the dismissal of the <code>SecondViewController</code>. Any suggestions?</p> ## edited <p>OK, more weird is that I tried <code>[self.tableView reloadData]</code> inside <code>- (void)viewDidAppear:(BOOL)animated</code>. The new tableViewCell still doesn't display its label properly; however, after waiting for 30 seconds, the label just magically pops up! Does this means that my iPhone/iPhone simulator needs time to think much?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload