2017-10-15 45 views
0

我有3個viewControllers:firebase解僱在Swift中重新加載表?

VcA:我用數據庫中的觀察員讀取數據,並通過與segue VcB。

VcB:我讀取數據並顯示它,用一個按鈕調用VcC來更新帶有segue的數據傳遞數據。

VcC:一個靜態tableview在我更新數據並保存它們。

問題是,當我保存VcC後退出並回到VcB時,所有數據都是舊的,即使在Firebase中所有數據都完全更新。

在VCB例如我讀到這樣的標題:

var groupName: String? 

比didAppear:

Name.title = groupName 

無論如何,如果我還回去從VCB到VCC表中的所有數據都舊數據。

更清楚:

我稱之爲VCA數據庫

enter image description here

在表中單擊名稱,並通過數據於VCB,一切都很好,現在,標題和其他瓦爾都OK

enter image description here

現在我點擊編輯和調用VCC,該表在那裏我更新數據,進行更改並保存,

enter image description here

保存VCC解僱後,我回去VCB - >標題仍然是P2,但火力不!

enter image description here

我再次點擊編輯以返回到VCC(編輯表),標題是舊

enter image description here

我認爲我必須記得從數據庫DATAS ..無論如何做到這一點,而無需刷新Firebase的數據?

我知道,如果我保存後一切都恢復正常,但我真的需要去VcB,我該怎麼辦?

我發現很多線程,這是最相似的,但沒有確切的情況... Reload tableView after dismiss a viewController

+0

貴國是否能在那裏你試圖讀取數據的VCB的代碼? – Woof

+0

使用「委託」。當您返回VcB時,您將能夠從VcC調用reloadData。 – Torewin

+0

@Woof我加了我如何閱讀代碼 – HaVaNa7

回答

0

如果我能正確地遵循本。

VCC:

protocol %NAME%Delegate 
{ 
    func reloadData() 
} 


class VcC: UIViewController /*(or table)*/{ 
    var mDelegate : %NAME%Delegate? 


    //in the func you use to dismiss self (VcC) 
    //mDelegate?. reloadData() 

} 

VCB:

class VcB: UIViewController /* (or table)*/,%NAME%Delegate { 
    func reloadData(){ 
     tableView.reloadData() 
     //OR 
     //Observer for Firebase here to gather the new information. Make sure to reset all datasources if you do this. 
    } 
} 
+0

thnx但在VcB我有一個簡單的ViewController不是表,該表僅在VcC – HaVaNa7

+0

它會工作,不管。我只是不知道要添加哪個課程。它將與'view'和'table'一起工作。 – Torewin

+0

我做到了,但是當我到達VcB時,標題仍然是舊的,也許我的解僱方法有問題? _ = navigationController?.popViewController(animated:true) – HaVaNa7