Update the data of a TableViewController after add

2019-08-05 10:42发布

问题:

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?

回答1:

Try this:

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