2011-03-14 47 views
2

是否可以更改/替換UITabBarController中某個選項卡的ViewContoller(和View)?爲TabBarItem更改ViewController

我想從一個特定的選項卡(這就是爲什麼NavigationController是不可能的)以任何順序在3個不同的ViewControllers之間切換。

回答

3

它們使用setViewControllers設置(大量):animated:所以你可以做這樣的事情。

// Assume tabController is the tab controller 
// and newVC is the controller you want to be the new view controller at index 0 
NSMutableArray *newControllers = [NSMutableArray arrayWithArray:tabController.viewControllers]; 
[newControllers replaceObjectAtIndex:0 withObject:newVC]; 
[tabController setViewControllers:newControllers animated:YES]; 

希望有幫助。

+0

謝謝!它取代了ViewController。但TabBarItem已經恢復,圖標/文本消失了。 我是從一個屬於tabBarItem的ViewControllers中做到這一點的,這可能不好嗎? –

相關問題