展开Segue以重新加载更新的表视图单元格



我有一个表视图,它有一个"添加"按钮,你点击添加按钮,一个新的视图控制器模式打开,你输入文本字段(姓名、职位、评级等),当你点击保存时,它会带你进入玩家配置文件页面,其中包含你在"添加视图控制器"中输入的所有信息。"我在玩家配置文件页面上还有一个Unwind Segue,可以让你回到列出你添加的所有玩家的表格视图。我的问题是,当我点击退到表格视图的按钮时,它不会添加新玩家。IE如果我的表格视图中有3个玩家要启动,我会点击添加添加第四个,输入信息并点击保存,然后被带到玩家配置文件页,当我点击展开按钮,表格视图仍然列出3,而不是4。下面是我的Unwind代码。。。

@IBAction func unwindToRecipeList(segue: UIStoryboardSegue) {
    if let sourceViewController = segue.sourceViewController as? RecipeDetailViewController, recipe = sourceViewController.recipe {
        if let selectedIndexPath = tableView.indexPathForSelectedRow {
            recipes[selectedIndexPath.row] = recipe
            tableView.reloadRowsAtIndexPaths([selectedIndexPath], withRowAnimation: .None)
        } else {
            let newIndexPath = NSIndexPath(forRow: recipes.count, inSection: 0)
            recipes.append(recipe)
            tableView.insertRowsAtIndexPaths([newIndexPath], withRowAnimation: .Bottom)
        }

在将配方附加到配方后尝试使用tableView.beginUpdates()tableView.endUpdates()

    @IBAction func unwindToRecipeList(segue: UIStoryboardSegue) {
    if let sourceViewController = segue.sourceViewController as? RecipeDetailViewController, recipe = sourceViewController.recipe {
        if let selectedIndexPath = tableView.indexPathForSelectedRow {
            recipes[selectedIndexPath.row] = recipe
            tableView.reloadRowsAtIndexPaths([selectedIndexPath], withRowAnimation: .None)
        } else {
            recipes.append(recipe)
            tableView.beginUpdates()
            tableView.insertRowsAtIndexPaths([NSIndexPath(forRow: recipes.count-1, inSection: 0)], withRowAnimation: .Automatic)
            tableView.endUpdates()
        }
    }
    }

最新更新