1

I have tableView (A) responsible for listing items CoreData and viewController (B) to add new item. To create a ViewController (B) custom, they chose to use the following Present Modally to use presentation Over Current Context to enable transparent background and be able to apply the blur.

  • From tableView (A) press the button to add a new item, the viewController (B) appears.
  • Add a new item and saved in CoreData
  • The viewController (B) execute self.dismissViewControllerAnimated(true, completion: nil) and the display returns to the tableView (B)

The problem is that the table view does not update the data.

Following a post from Stack Overflow resulting in code:

override func viewDidAppear(animated: Bool) {
    self.loadData()
}

But at the back of viewController (B), nothing happens in Xcode does not pass the lines of viewDidAppear.

Can anyone help me?

James
  • 1,114
  • 1
  • 12
  • 34
  • I read your question there times, and I still do not understand your question. – Jody Hagins Oct 16 '15 at 12:36
  • 1
    You should use an `NSFetchedResultsController` to populate your tableView. If you use its delegate methods (there is boilerplate code in the Apple docs), it will automatically update the TV as soon as you add the new object. – pbasdf Oct 16 '15 at 19:30
  • @pbasdf The problem is not in the loading data in tableView, is in the back of a sigue (ViewController to add an item to CoreData) – James Oct 17 '15 at 19:11
  • 1
    @James Yes. As I understand it, you want the tableView in vc A updated when vc B is dismissed. But if you use NSFetchedResultsController in vc A, you do not need to rely on lifecycle methods like viewDidAppear to trigger the update - the FRC will do it for you. – pbasdf Oct 17 '15 at 20:32
  • @pbasdf You could post an answer with an example of use of `NSFetchedResultsController`? – James Oct 18 '15 at 00:03
  • @James Sure - if you edit your post to include your current tableView methods, I can work up an answer based on FRC – pbasdf Oct 18 '15 at 21:19

1 Answers1

1

Try this:

 override func viewDidAppear(animated: Bool)
{
    self.yourTableViewName.reloadData()
}
Tommyizua
  • 346
  • 1
  • 5