2011-09-06 44 views
0

如何從兩個TabBar項目調用相同的ViewController?如何從兩個TabBar項目調用相同的ViewController?

我使用:

MyViewController * VC1 = [[MyViewController的alloc] initWithNib:@ 「MyViewController」 束:無]; MyViewController * vc2 = [[MyViewController alloc] initWithNib:@「MyViewController」bundle:nil];

的UITabBarController分頁* = [[ALLOC的UITabBarController] INIT]; [tabs setViewControllers:[NSArray arrayWithObjects:vc1,vc2,nil] animated:NO];

但變量將被重置,我想保持的變量。

我的視圖控制器包含的TableView用的ListData,我只是想表明前三他們當我點擊一個第二的TabBar,但計算ListData變量復位,併成爲零。

是否有修復? 感謝

+1

所以你想在兩個標籤中顯示相同的東西?爲什麼有兩個單獨的選項卡呢? – SVD

+0

因爲一個是顯示的tableView的所有數據,而另一種是用於表示具體數據的tableView(如喜歡的物品) – Houranis

回答

0

我不知道爲什麼你會做到這一點,但是這可能工作。

MyViewController *vc1 = [[MyViewController alloc] initWithNib:@"MyViewController" bundle:nil]; 

UITabBarController *tabs = [[UITabBarController alloc] init]; 
[tabs setViewControllers:[NSArray arrayWithObjects:vc1, vc1, nil] animated:NO]; 
+0

它沒有工作的方式,它顯示兩個選項卡,但只有一個是工作,第二個是無效。 – Houranis

+0

我的猜測是,類的UITabBarController不支持,我建議你找到另一種方式來實現你正在嘗試做的,也許一個單用於填充兩個視圖控制器的表,或者類似的東西。另外,即使你管理它這樣工作,蘋果可能會拒絕它。 – EmilioPelaez

+0

我用單身,它的工作。 – Houranis

0

你可以有視圖控制器的一個是另一個的子類,子類將有一些數據過濾掉。 UITabBarController有一個委託方法,它在標籤之間切換時調用 - 您可以使用它來根據需要填充列表。

相關問題