Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to reload the tableview after the user has added a new row - using core data constructs
    text
    copied!<p>I'm using core data and I have a simple two-entity model. My navigation controller has an "add" button that allows the user to add new school years to the database... (i.e. freshman year, sophomore year, etc...)</p> <p>When the user clicks the add button, I call this function which pushes my simple data entry form onto the stack. Works great. User adds new school year and clicks the "done" button on the form. I pop that form off the stack and the user comes back to the main screen.</p> <p>My problem is that the main screen (tableview) does not show the new entry in the table. How do I make the code refresh the table? Note: If I exit the simulator and relaunch it, the new record is then visible.</p> <p>Here is the function I call when the user clicks the "+" sign to add a new school year.</p> <pre><code>- (void)addSchoolYear { vcAddYear *addYearViewController = [[vcAddYear alloc] initWithNibName:@"vcAddYear" bundle:nil]; [self.navigationController pushViewController:addYearViewController animated:YES]; [addYearViewController release]; } </code></pre> <p>When the user is done adding the new record and then clicks on the "Save" button. Here is that function.</p> <pre><code>- (void)SaveButton { //get a pointer to the managedobjectcontext GradetrackAppDelegate *AppDelegate = (GradetrackAppDelegate *)[[UIApplication sharedApplication] delegate]; managedObjectContext = AppDelegate.managedObjectContext; Schoolyear *schoolyear = (Schoolyear *)[NSEntityDescription insertNewObjectForEntityForName:@"Schoolyear" inManagedObjectContext:managedObjectContext]; // plug the user's data into a schoolyear record [schoolyear setNameForThisYear: _nameYear.text]; [schoolyear setSchoolName: _nameSchool.text]; NSError *error = nil; if (![managedObjectContext save:&amp;error]) { // Handle the error. } //[AppDelegate.delegateSchoolyearsArray insertObject:schoolyear atIndex:0]; [self.navigationController popViewControllerAnimated:YES]; return; } </code></pre> <p>At this point, my code returns to the calling rootviewcontroller which is a tableview and the table looks just like it did before the user added the new record. How do I tell my tableview to reload and show the new data item along with the other old ones?</p> <p>Many thanks.</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