根據Apple,我可以結合UINavigationController
和UITabBarController
使用的代碼,例如。我應該使用一個單獨的UINavigationController每個標籤欄
MyViewController1* vc1 = [[MyViewController1 alloc] init];
MyViewController2* vc2 = [[MyViewController2 alloc] init];
MyViewController3* vc3 = [[MyViewController3 alloc] init];
MyNavRootViewController* vc4 = [[MyNavRootViewController alloc] init];
UINavigationController* navController = [[UINavigationController alloc]
initWithRootViewController:vc4];
NSArray* controllers = [NSArray arrayWithObjects:vc1, vc2, vc3, navController, nil];
tabBarController.viewControllers = controllers;
在這種設置中,只有VC4有UINavigationController
,但如果我想VC1-VC3也有UINavigationController
?,我應該做的一樣..
MyViewController1* vc1 = [[MyViewController1 alloc] init];
UINavigationController* nv1 = [[UINavigationController alloc]
initWithRootViewController:vc1];
MyViewController1* vc2 = [[MyViewController2 alloc] init];
UINavigationController* nv2= [[UINavigationController alloc]
initWithRootViewController:vc2];
MyViewController1* vc3 = [[MyViewController3 alloc] init];
UINavigationController* nv3 = [[UINavigationController alloc]
initWithRootViewController:vc3];
NSArray* controllers = [NSArray arrayWithObjects:nv1, nv2, nv3, nil];
tabBarController.viewControllers = controllers;
這是正確的方法?
那麼,這取決於這是你想要的...我不會說這種方法是錯誤的,但也許它不會給你可能預期的結果和/或有更好的方法。你的目標是什麼? – Saphrosit
如果您必須在單個Tab中瀏覽很多視圖,那麼您需要使用navigationController。如果每個選項卡都顯示單個ViewController,則不要使用navigationController。這完全取決於你的要求是什麼。 –