Table view not refreshed after dismissing popover?

I've been bashing my head for some time now because of this issue. I am detailing my scenario.

I have a table view where I can add data using a popover that is displayed when I click the "+" button in the navigation bar. I am getting values ​​from a popover, but where I am stuck, the resulting data is not reflected in the table view. If I move back and forth, it is displayed. Tried to reload the table with different options, but nothing works.

If you want a taste of my code, you can get it here. Stored data not showing in table view with one to multiple key data relationship?

Can anyone please solve my problem, help is greatly appreciated.

+1


source to share


1 answer


The idea here is to give the Add Commands View Manager the Show Command Table Manager command to reload its table view.



  • In the Add Team VC quick build file, define the protocol:

    protocol AddTeamsDelegateProtocol {
        func didAddTeam()
    }
    
          

  • In the Add Team class, add a new property of delegate

    this type:

    var delegate : AddTeamsDelegateProtocol? = nil
    
          

  • In the same class, call the delegate method when the new command is saved:

    @IBAction func submit(sender: AnyObject) {
        let entity = NSEntityDescription.entityForName("Teams", inManagedObjectContext: managedObjectContext)
        let team = Teams(entity: entity!, insertIntoManagedObjectContext: managedObjectContext)
        team.teamName = teamNamePO.text
        team.teamImage = teamImagePO.image
        do{
            try managedObjectContext.save()
        } catch let error as NSError{
            print("\(error), \(error.userInfo)")
        }
        self.delegate?.didAddTeam()
        dismissViewControllerAnimated(true, completion: nil)
    }
    
          

  • In the Team table view controller, implement the method didAddTeam()

    :

    func didAddTeam() {
        let request = NSFetchRequest(entityName: "Teams")
        do{
            teamData = try managedObjectContext.executeFetchRequest(request) as! [Teams]
        } catch let error as NSError {
            print("\(error), \(error.userInfo)")
        }
        self.tableView.reloadData()
    }
    
          

  • Make sure the view controller of the Team table conforms to the protocol

    class GroupTable: UITableViewController, NSFetchedResultsControllerDelegate, AddTeamsDelegateProtocol {
    
          

  • Before moving on to (or presenting) the Add Commands command (I couldn't see how this is done in your code in another question), set the Add Commands controller delegate:

    addTeamsVC.delegate = self
    
          

+3


source







All Articles