UITabBar Showing More Icons Instead of "More" Option - ios

I'm currently attempting to use the UITabBar for an iOS app that contains 7 tabBar Items.
When I use the storyboard, I am able to achieve all 7 tabBarItems.
When I programmatically add the tabBarItems, It forces a "More" Button to access the other tabBarItems.
Is there a way programmatically keep all the 7 tabBarItems as when I am manually create the UITabBar?
The Code that I'm using to build the uitabbar in my appdelegate.m
self.tabBarController = [[UITabBarController alloc] init];
FirstViewController *firstVC = [[FirstViewController alloc] init];
SecondViewController *secondVC = [[SecondViewController alloc] init];
ThirdViewController *thirdVC = [[ThirdViewController alloc] init];
FourthViewController *fourthVC = [[FourthViewController alloc] init];
FifthViewController *fifthVC = [[FifthViewController alloc] init];
SixthViewController *sixthVC = [[SixthViewController alloc] init];
SeventhViewController *seventhVC = [[SeventhViewController alloc] init];
NSArray *controllers = #[firstVC, secondVC, thirdVC, fourthVC, fifthVC, sixthVC, seventhVC];
self.tabBarController.viewControllers = controllers;
self.window.rootViewController = self.tabBarController;
[_window addSubview:_tabBarController.view];

By design you are limited to 5, from apple docs
If you add more than five items to the viewControllers property, the
tab bar controller automatically inserts a special view controller
(called the More view controller) to handle the display of the
additional items. The More view controller provides a custom interface
that lists the additional view controllers in a table, which can
expand to accommodate any number of view controllers. The More view
controller cannot be customized or selected and does not appear in any
of the view controller lists managed by the tab bar controller. It
appears automatically when it is needed and is separate from your
custom content. You can get a reference to it though by accessing the
moreNavigationController property of UITabBarController.
It just not recommended , but if you insist you will need to use a library or perhaps use a tool bar and add many UIBarButtonItems to it.

Related

How to display more than 4 tabs in a single row without having "More" option iOS [duplicate]

I'm currently attempting to use the UITabBar for an iOS app that contains 7 tabBar Items.
When I use the storyboard, I am able to achieve all 7 tabBarItems.
When I programmatically add the tabBarItems, It forces a "More" Button to access the other tabBarItems.
Is there a way programmatically keep all the 7 tabBarItems as when I am manually create the UITabBar?
The Code that I'm using to build the uitabbar in my appdelegate.m
self.tabBarController = [[UITabBarController alloc] init];
FirstViewController *firstVC = [[FirstViewController alloc] init];
SecondViewController *secondVC = [[SecondViewController alloc] init];
ThirdViewController *thirdVC = [[ThirdViewController alloc] init];
FourthViewController *fourthVC = [[FourthViewController alloc] init];
FifthViewController *fifthVC = [[FifthViewController alloc] init];
SixthViewController *sixthVC = [[SixthViewController alloc] init];
SeventhViewController *seventhVC = [[SeventhViewController alloc] init];
NSArray *controllers = #[firstVC, secondVC, thirdVC, fourthVC, fifthVC, sixthVC, seventhVC];
self.tabBarController.viewControllers = controllers;
self.window.rootViewController = self.tabBarController;
[_window addSubview:_tabBarController.view];
By design you are limited to 5, from apple docs
If you add more than five items to the viewControllers property, the
tab bar controller automatically inserts a special view controller
(called the More view controller) to handle the display of the
additional items. The More view controller provides a custom interface
that lists the additional view controllers in a table, which can
expand to accommodate any number of view controllers. The More view
controller cannot be customized or selected and does not appear in any
of the view controller lists managed by the tab bar controller. It
appears automatically when it is needed and is separate from your
custom content. You can get a reference to it though by accessing the
moreNavigationController property of UITabBarController.
It just not recommended , but if you insist you will need to use a library or perhaps use a tool bar and add many UIBarButtonItems to it.

navigating to ViewControllers that aren't on the UITabBar

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.
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.

SplitViewController in only one of the existing 5 views?

I have 5 views in my app and I'm appDelegate by setting them in the following way:
UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects:navigationcontroller1, navigationcontroller7, navigationcontroller5, navigationcontroller4, navigationcontroller6, navigationcontroller2, nil];
self.window.rootViewController = tabBarController;
All of them come with a NavigationController and tabbarcontroller, But I needed to split the screen into two parts, in this case the screen would be divided would be navigationcontroller2, as you can see below:
VendaViewController *venda_viewcontroller = [[VendaViewController alloc] init];
UINavigationController *navigationcontroller2 = [[UINavigationController alloc] init];
[navigationcontroller2 pushViewController:venda_viewcontroller animated:YES];
Hence I tried the following way:
VendaViewController *venda_viewcontroller = [[VendaViewController alloc] init];
VendaDetailViewController *vendaDetail_viewcontroller = [[VendaDetailViewController alloc] init];
UISplitViewController *splitVC = [[UISplitViewController alloc] init];
[splitVC setViewControllers:[NSArray arrayWithObjects:venda_viewcontroller,vendaDetail_viewcontroller,nil]];
UINavigationController *navigationcontroller2 = [[UINavigationController alloc] init];
[navigationcontroller2 pushViewController:splitVC animated:YES];
But not work in this code, but in documentation of UISplitViewController is writing the following message:
"you must always install the view from a UISplitViewController object
as the root view of your application’s window. [...] Split view
controllers cannot be presented modally."
So...If I like to put a splitViewController in my view controller, I'll have to put splitViewController in all of my views controllers? Or have another solution to this?
You can use a UISplitViewController only as the root view controller of your app. In your case you can implement your custom container view controller with functionality similar to the split (two subview controller inside the main). Follow this link for details.

How to display something in a root view in ios using storyboard?

I am creating an application in ios using storyboard. I have a Tab Bar Controller as my root view, from this page I can navigate to other pages using the tabs, but how can I insert any text or image in the root view for the tab bar controller.
The default page (or root page as you are putting it) for a tab bar controller is one of the other UIViewControllers only. A UITabBarController can show another UIViewController inside it. There can be no text or image right inside a UITabBarController, but there can be a UIViewController inside it which has text or images. It is just a container for other view controllers.
Check out this example, it will help simplify things.
FirstViewController *fistView = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
SecondViewController *secondView = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
NSArray *viewControllersArray = [[NSArray alloc] initWithObjects:fistView, secondView, nil];
self.tabController = [[UITabBarController alloc] init];
[self.tabController setViewControllers:viewControllersArray animated:YES];
In the code above, the firstView controller will be displayed initially in the tabController, so what you want to do is add text and images and stuff inside firstView's xib file (or code).

iOS put a TabbarViewController into a NavigationController but the navigationBar is nil

A is a subclass of TabbarViewController
A *a = [[A alloc] init];
B *b = [[B alloc] init];
C *C = [[C alloc] init];
NSArray *viewControllers = [NSArray arrayWithObjects:b,c, nil];
[a setViewControllers:viewControllers];
UINavigationController *nv =[[UINavigationController alloc] initWithRootViewController:a];
nv.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:nv animated:YES completion:nil];
And in A.m: I find the a.navigationController.navigationBar is nil
I dont know why?
Normally, you should create several NavigationController objects for each of TabBarController's tabs.
When you create a navigation interface, you need to decide how you intend to use a navigation interface. Because it imposes an overarching organization on your data, you should only use it in these specific ways:
Install it directly as a window’s root view controller.
Install it as the view controller of a tab in a tab bar interface.
Install it as one of the two root view controllers in a split view interface. (iPad only)
Present it modally from another view controller.
Display it from a popover. (iPad only)
If you still want 'TabBarController inside NavigationController' functionality, please, read this or this SO questions to find a proper solution.

Resources