Pregunta

I started using UITabBarController and it is great.

The thing is I have a few views that aren't accessed from the UITabBar (either presented modal programatically or we want to have a button on the top to jump to them)

The thing is that I want to retain the Tab bar visible in these views.
From my understanding mixing presentViewController and UITabBarController is problematic.

How can I do that? Can I have "hidden" tab bar elements I can reference programatically?

Just to clarify with an example:

Views A,B,C,D are in the tab bar - via the storyboard - everything is peachy.
I NEED to have views E and F clickable from the top navigation (please don't suggest a sliding TabBar or a multiple line UITabBar).
I could just jump to E and F but I want the UITabBar to still be visible so the user can jump from E to A for example.

¿Fue útil?

Solución

Just use the good old UINavigationController for every tab and just use [self.navigationController pushViewController:A animated:YES];

That's how the setup looks in code:

SGTabBarViewController *rootVC = [[SGTabBarViewController alloc] init];

SGFirstTabViewController *firstVC = [[SGFirstTabViewController alloc] init];
UINavigationController *navController1 = [[UINavigationController alloc] initWithRootViewController:firstVC];
SGSecondTabViewController *secondVC = [[SGSecondTabViewController alloc] init];
UINavigationController *navController2 = [[UINavigationController alloc] initWithRootViewController:secondVC];
SGThirdTabViewController *thirdVC = [[SGThirdTabViewController alloc] init];
UINavigationController *navController3 = [[UINavigationController alloc] initWithRootViewController:thirdVC];
SGForuthTabViewController *fourhtVC = [[SGForuthTabViewController alloc] init];
UINavigationController *navController4 = [[UINavigationController alloc] initWithRootViewController:fourhtVC];

rootVC.viewControllers = @[navController1, navController2, navController3, navController4];

self.window.rootViewController = rootVC;
[self.window makeKeyAndVisible];

If you want your UITabBar visible on every VC you push just use hidesBottomBarWhenPushed = NO; on it.

However, there is no way to have UITabBar visible on views presented modally.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top