2016-05-03 70 views
0

我有表格視圖有一個「添加」按鈕,你點擊添加按鈕和一個新的視圖控制器模態地打開,你輸入文本字段(名稱,位置,評級,等等......),當你點擊保存它會帶你進入包含你在「添加視圖控制器」中輸入的所有信息的玩家個人資料頁面。我還在玩家個人資料頁面上有一個Unwind Segue讓你回到這個表格視圖列出了你添加的所有球員,我的問題是當我點擊鬆開回表格視圖的按鈕時,它不會添加新的球員IE如果我的表格視圖中有3名球員開始,我點擊add添加第四個,輸入信息並點擊保存,然後進入播放器配置文件頁面,當我點擊展開按鈕時,表格視圖仍列出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) 
     } 

回答

0

使用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() 
     } 
    } 
    } 
+0

還不行。我是否必須以不同的方式將數據傳回我的表格視圖? –

+0

你是否正確地從你的sourceviewcontroller獲得配方?,你可以在你的else語句中打印嗎?,然後在追加配方後打印配方。 – valencieu

相關問題