[英]how to change UIViewController in a Tab of TabBarController
我有一個帶有TabBar和選項卡的iPhone應用程序。 每個選項卡都加載有UIViewControllers,我想要的特定選項卡是更改與選項卡關聯的UIViewController。 當我調用PresentViewController時,它會更改UIViewController,但還會隱藏我不想要的TabBar。
有人可以解釋需要做什么嗎?
謝謝
UITabBarController在適當地名為viewControllers
的屬性中保留其視圖控制器的viewControllers
。 您可以在運行時修改它。 有一些副作用可能適合您的應用程序, 但是請務必閱讀文檔 。
便捷方法(以及如何修改不可變數組的說明)如下所示:
- (void)replaceTabBarViewControllerAtIndex:(NSUInteger)index with:(UIViewController *)newVC {
NSMutableArray *newVCs = [NSMutableArray arrayWithArray:self.tabBarController.viewControllers];
if (index < newVCs.count) {
newVCs[index] = newVC;
self.tabBarController.viewControllers = [NSArray arrayWithArray:newVCs];
}
}
用新的vc調用它而不顯示它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.