2010-12-19 73 views
1

我已經實現了一個基於導航的視圖控制器與幾個視圖和模型。Tabbar具有相同的導航控制器

現在我通過界面生成器將我的導航控制器添加到Tabbar。 (只是把所有的東西拖進去)。它的工作,我有一個新的標籤,其中包含我的所有觀點。

但現在我想再次添加完全相同的導航視圖控制器到另一個選項卡。我也可以這樣做,問題是,當我例如刪除我的表格視圖中的條目,該條目在其他選項卡中仍然可見。

所以當我切換選項卡時,需要更新模型的方法。

更新:

我在RootViewController添加addObserver包含表視圖。我把它放在「view did load」中,在我的delete方法中是postNotification。沒有編譯錯誤,但表格也不互相更新。

我上傳我的項目,也許你可以看看?:

http://www.perry-paul.de/unternehmenf.zip

這樣的

回答

2

一種方式是通過使用NSNotifications

當加載包含的tableView您的視圖控制器,使用

[[NSNotificationCenter defaultCenter] addObserver:self.tableView selector:@selector(reloadData) name:@"ModelUpdated" object:nil];

這樣[self.tableView reloadData]將被調用每次發佈「ModelUpdated」通知時間註冊您的tableView的通知。所以,當你刪除一個條目,發送使用

[[NSNotificationCenter defaultCenter] postNotificationName:@"ModelUpdated" nil];

最後的通知,不要忘記刪除(通常在viewDidUnload)通知:

[[NSNotificationCenter defaultCenter] removeObserver:self name:"ModelUpdated" object:nil];

更多信息上NSNotifications在這個問題:What is NSNotification?

+0

Hy,thx爲您的快速回復。 – Subseven 2010-12-20 01:18:01