消除弹出窗口后,表格视图没有更新吗? [英] Table view is not getting updated after dismissing the popover?

查看:71
本文介绍了消除弹出窗口后,表格视图没有更新吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于这个问题,我要摸了一段时间。我会详细说明我的情况。

I'm banging my head for some time due to this issue. I precise my scenario in detail.

我有一个表格视图,可以在其中使用弹出窗口添加数据,该弹出窗口通过单击导航栏中的 +按钮显示。我从弹出窗口中获取了值,但我遇到的问题是,接收到的数据没有反映在表格视图中。如果我来回移动,它将显示出来。试图用不同的可能性重新加载表,但是没有用。

I have a table view where I can add data using a popover which gets displayed on clicking the '+' button in the navigation bar. I get the values from the popover but where I'm stuck is, the data received is not getting reflected in the tableview. If I move back and forth it gets displayed. Tried to reload the table with different possibilities but nothing works.

如果您确实想尝一尝我的代码,可以在这里获取它存储的数据无法在表中显示视图,在核心数据的一对多关系中?

If you do want a taste of my code, you can get it here Data stored fails to display in the table view, in one to many relationship of core data?

任何人都可以解决我的问题,非常感谢帮助。

Could anyone solve my problem, help is very much appreciated.

推荐答案

此处的想法是为添加团队弹出窗口视图控制器提供一种方法,以告知团队表视图控制器重新加载其表视图。

The idea here is to provide a way for the Add Teams popover view controller to tell the Team table view controller to reload its table view.


  1. 在添加团队VC快速文件中,定义一个协议:

  1. In the Add Team VC swift file, define a protocol:

protocol AddTeamsDelegateProtocol {
    func didAddTeam()
}


  • 在添加团队类中,添加一个新的 delegate 属性,该属性的类型为:

  • In the Add Team class, add a new delegate property which of this type:

    var delegate : AddTeamsDelegateProtocol? = nil
    


  • 在同一类中,保存新团队后调用委托方法:

  • In the same class, call the delegate method when the new Team 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)
    }
    


  • 在团队表视图控制器中,实现 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()
    }
    


  • 确保Team table视图控制器符合协议

  • Ensure that the Team table view controller conforms to the protocol

    class GroupTable: UITableViewController, NSFetchedResultsControllerDelegate, AddTeamsDelegateProtocol {
    


  • 在选择(或展示)添加团队弹出窗口之前(在另一个问题中我看不到您的代码是如何做到的),请设置添加团队控制器的代表:

  • Before segueing to (or presenting) the Add Teams popover (I couldn't see how this is done in your code in the other question), set the Add Teams controller's delegate:

    addTeamsVC.delegate = self
    


  • 这篇关于消除弹出窗口后,表格视图没有更新吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆