UITabBarController initially highlights all tab bar item images - ios

I'm programmatically instantiating a UITabBarController that will manage 2 view controllers, and then setting it as the rootViewController. However when the views appear, it highlights all the tab item's images (although the text is properly highlighted). No matter what I set to the selectedIndex the images will all appear highlighted. Only when you tap on the tab bar items does it actually toggle the highlighted state on the images. What's going on here?
Code:
UITabBarController *tabController = [[UITabBarController alloc] init];
UIStoryboard *storyboard = [self storyboard];
OGVideoStreamViewController *questionsController = [storyboard instantiateViewControllerWithIdentifier:#"OGVideoStreamViewController"];
questionsController.isQuestion = YES;
OGVideoStreamViewController *answersController = [storyboard instantiateViewControllerWithIdentifier:#"OGVideoStreamViewController"];
answersController.isQuestion = NO;
OGMatchesViewController *matchesController = [[OGMatchesViewController alloc] initWithNibName:#"OGMatchesViewController" bundle:nil];
questionsController.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"Questions" image:[UIImage imageNamed:#"Tab Icon - Questions"] tag:0];
answersController.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"Answers" image:[UIImage imageNamed:#"Tab Icon - Answers"] tag:1];
matchesController.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"Inbox" image:[UIImage imageNamed:#"Tab Icon - Inbox"] tag:2];
[tabController setViewControllers:#[questionsController, answersController, matchesController] animated:NO];
tabController.selectedViewController = questionsController;
[[UIApplication sharedApplication] keyWindow].rootViewController = tabController;

I've had the same problem and it was due to me calling:
[UIView appearance].tintColor = [UIColor colorWithRed:1.000
green:0.793
blue:0.236
alpha:1.000];
I called it in my AppDelegate, so i could change it to the following:
self.window.tintColor = [UIColor colorWithRed:1.000
green:0.793
blue:0.236
alpha:1.000];

Related

UITabbar disappears when i push view controller

This is my app delegate:
// Initialize your five tab controllers. with each tab has its own navigation controller
HomePageView *homePageView = [[HomePageView alloc]init];
UINavigationController *nav1 = [[UINavigationController alloc]initWithRootViewController:homePageView];
[nav1.navigationBar setTitleTextAttributes:#{NSForegroundColorAttributeName : [UIColor whiteColor]}];
// Set nav Bar to be completely transparent
[nav1.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
nav1.navigationBar.shadowImage = [UIImage new];
nav1.navigationBar.translucent = YES;
//Set Title
nav1.tabBarItem.title = #"Home";
ProfileViewController *profileViewController=[[ProfileViewController alloc]init];
UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:profileViewController];
// Set Title
nav2.tabBarItem.title = #"Profile";
// Set nav Bar to be completely transparent
[nav2.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
nav2.navigationBar.shadowImage = [UIImage new];
nav2.navigationBar.translucent = YES;
FeedViewController *feedViewController=[[FeedViewController alloc]init];
UINavigationController *nav3 = [[UINavigationController alloc]initWithRootViewController:feedViewController];
// Set nav Bar to be completely transparent
[nav3.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
nav3.navigationBar.shadowImage = [UIImage new];
nav3.navigationBar.translucent = YES;
// Set Title
nav3.tabBarItem.title = #"Feeds";
ListeningSessionViewController *listeningSessionViewController= [[ListeningSessionViewController alloc]init];
UINavigationController *nav4 = [[UINavigationController alloc]initWithRootViewController:listeningSessionViewController];
// Set nav Bar to be completely transparent
[nav4.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
nav4.navigationBar.shadowImage = [UIImage new];
nav4.navigationBar.translucent = YES;
// set Title
nav4.tabBarItem.title = #"Mussion";
RecievedViewController *recievedViewController =[[RecievedViewController alloc]init];
UINavigationController *nav5 = [[UINavigationController alloc]initWithRootViewController:recievedViewController];
// Set nav Bar to be completely transparent
[nav5.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
nav5.navigationBar.shadowImage = [UIImage new];
nav5.navigationBar.translucent = YES;
// Set Title
nav5.tabBarItem.title = #"Recieved";
// Set selected tab bar background
UIImage *whiteBackground = [UIImage imageNamed:#"whiteBackground"];
[[UITabBar appearance] setSelectionIndicatorImage:whiteBackground];
self.tabC.tabBar.translucent = YES;
// initialize tabbarcontroller,set your viewcontrollers and change its color.
self.tabC = [[UITabBarController alloc]init];
NSArray* controllers = [NSArray arrayWithObjects: nav1,nav2,nav3,nav4,nav5, nil];
[self.tabC setViewControllers: controllers animated:NO];
//[_window addSubview:self.tabC.view];
[self.window setRootViewController:self.tabC];
// Show window
[self.window makeKeyAndVisible];
return YES;
}
When i push a view controller from one of the tabbar controllers eg HomePageView, The tabbar disappears:
SearchSongViewController *Search_MusicTableView = [[SearchSongViewController alloc] init];
Search_MusicTableView.modalTransitionStyle=UIModalTransitionStyleCrossDissolve;
[self.navigationController presentModalViewController:Search_MusicTableView animated:YES];
When i present the modal view or even push another view controller, the tabbar disappears, please why is this ? and how do i fix it, Thanks alot !

Button to Present ViewController After Tutorial (which Loads For 1st Time Only)

I have a tutorial ViewController called tutorialViewController which only presents itself for the first time the app is launched. This is how I do that:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
BOOL hasRunBefore = [defaults boolForKey:#"FirstRun"];
if (!hasRunBefore) {
[defaults setBool:YES forKey:#"FirstRun"];
self.window.rootViewController = [tutorialViewController new];
self.window.backgroundColor = [UIColor whiteColor];
// RESideMenu Stuff that Must Be Done
leftSideMenuViewController *leftMenuViewController = [[leftSideMenuViewController alloc] init];
rightSideMenuViewController *rightMenuViewController = [[rightSideMenuViewController alloc] init];
musicPlayerViewController *navigationController = [[homeViewController alloc] init];
RESideMenu *sideMenuViewController = [[RESideMenu alloc] initWithContentViewController:navigationController
leftMenuViewController:leftMenuViewController
rightMenuViewController:rightMenuViewController];
sideMenuViewController.menuPreferredStatusBarStyle = 1;
sideMenuViewController.delegate = self;
sideMenuViewController.contentViewShadowColor = [UIColor blackColor];
sideMenuViewController.contentViewShadowOffset = CGSizeMake(0, 0);
sideMenuViewController.contentViewShadowOpacity = 0.6;
sideMenuViewController.contentViewShadowRadius = 12;
sideMenuViewController.contentViewShadowEnabled = YES;
self.window.backgroundColor = [UIColor blackColor];
}
else
{
NSLog (#"Not the first time this controller has been loaded");
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:[[homeViewController alloc] init]];
// RESideMenu Stuff that Must Be Done
leftSideMenuViewController *leftMenuViewController = [[leftSideMenuViewController alloc] init];
rightSideMenuViewController *rightMenuViewController = [[rightSideMenuViewController alloc] init];
RESideMenu *sideMenuViewController = [[RESideMenu alloc] initWithContentViewController:navigationController
leftMenuViewController:leftMenuViewController
rightMenuViewController:rightMenuViewController];
sideMenuViewController.menuPreferredStatusBarStyle = 1;
sideMenuViewController.delegate = self;
sideMenuViewController.contentViewShadowColor = [UIColor blackColor];
sideMenuViewController.contentViewShadowOffset = CGSizeMake(0, 0);
sideMenuViewController.contentViewShadowOpacity = 0.6;
sideMenuViewController.contentViewShadowRadius = 12;
sideMenuViewController.contentViewShadowEnabled = YES;
self.window.rootViewController = sideMenuViewController;
self.window.backgroundColor = [UIColor blackColor];
}
This works well so far - if I load the app for the first time, it shows tutorialViewController. If I close it and open it again, it shows homeViewController.
I'd just like to know how to add an IBAction to take me from tutorialViewController to homeViewController. Currently, I wrote this:
- (IBAction)goToHomeViewController:(id)sender {
homeViewController *navigationController = [homeViewController new];
[self presentViewController:navigationController animated:YES completion:^{
}];
NSLog(#"Start button pressed");
}
It presents homeViewController but it does not show the navigation bar, etc. - as it would if homeViewController was the rootViewController.
Here are some more details
tutorialViewController does not show a status bar or a navigation bar. It is simply a scrollview that takes up the whole screen.
'homeViewControllerhas a navigation bar with a left bar button and right bar button that brings up otherviewControllers`.
I've searched other SO questions but they are mostly to do with Storyboards, which I am not using. Just .xibs (and .h and .m).
How do I present homeViewController from tutorialViewController just as it would display if homeViewController was the rootViewController?
Wrap homeViewController in a UINavigationController should work.
[self presentViewController:[[UINavigationController alloc] initWithRootViewController:homeViewController] animated:YES: completion:nil]
You can also do like this.
In your 'if' condition add tutorialViewController as
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:[[tutorialViewController alloc] init]];
And in the goToHomeViewController function add,
homeViewController *navigationController = [homeViewController new];
[self.navigation pushViewController:navigationController animated:NO];
So first time the tutorialViewController act as rootview controller and if you want to hide NavigationBar add following code,
[[self navigationController] setNavigationBarHidden:YES animated:YES];

How to remove "more" option from tabbar controller without delete tabs in ios

I am using tab bar controller and i have 6 tabs when i run app at that time after 4 tab is displayed and there is more option but here i want displaying all tabs not want to display "more" in ios 7. the code is :
UIViewController *viewController1 = [[ViewController alloc]initWithNibName:#"ViewController" bundle:nil];
Calendar *viewController2 = [[Calendar alloc] initWithNibName:#"Calendar" bundle:nil];
nearby *viewController3 = [[nearby alloc] initWithNibName:#"nearby" bundle:nil];
offer *viewController4 = [[offer alloc] initWithNibName:#"offer" bundle:nil];
social *viewController5 = [[social alloc] initWithNibName:#"social" bundle:nil];
contact *viewController6 = [[contact alloc] initWithNibName:#"contact" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController1];
UINavigationController *navController1 = [[UINavigationController alloc] initWithRootViewController:viewController2];
UINavigationController *navController2 = [[UINavigationController alloc] initWithRootViewController:viewController3];
UINavigationController *navController3 = [[UINavigationController alloc] initWithRootViewController:viewController4];
self.tab = [[UITabBarController alloc] init];
self.tab.viewControllers = [NSArray arrayWithObjects:navController, navController1,navController2,navController3,viewController5,viewController6, nil];
[[self.tab tabBar] setBackgroundImage:[UIImage imageNamed:#"tabcrop.png"]];
self.tab.customizableViewControllers = nil;
[[[self.tab moreNavigationController] visibleViewController] setTitle:#""];
[self.tab.tabBar setTranslucent:YES];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:#"AmericanTypewriter" size:10.0f], UITextAttributeFont,
[UIColor yellowColor], UITextAttributeTextColor,
[UIColor redColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)], UITextAttributeTextShadowOffset,
nil] forState:UIControlStateSelected];
self.window.rootViewController = self.tab;
`
According to apple's docs it is not possible: https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/TabBarControllers.html
This is what it says:
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.
So try custom tab bar try this:
https://github.com/Marxon13/M13InfiniteTabBar

how to add tab bar controller from the second view controller [duplicate]

This question already has an answer here:
Showing login view controller before main tab bar controller
(1 answer)
Closed 9 years ago.
Im beginner to IOS app development learning.
I have a login screen as my first view controller and i need the second view controller to be a tab bar view controller .with 4 different tabs and i have 4 different XIB's for them.
some one help me to go ahead.
Best way you can do is Present the login screen modally when the app starts from your tab bar controller first screen, add code for presenting login screen in viewWillAppear and after login dismiss the screen. You can create TabBarController in appDelegate like this
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UITabBarController tabBarController=[[UITabBarController alloc] init];
FirstViewController *firstVC = [[UIViewController alloc] initWithNibName:#"FirstVC" bundle:nil];
UINavigationController *firstNavController = [[UINavigationController alloc] initWithRootViewController: firstVC];
SecondViewController *secondVC = [[UIViewController alloc] initWithNibName:#"secondVC" bundle:nil];
UINavigationController *secondNavController = [[UINavigationController alloc] initWithRootViewController:secondVC];
tabBarController.viewControllers = [NSArray arrayWithObjects: firstNavController, secondNavController, nil];
tabBarController.selectedIndex=0;
tabBarController.delegate = self;
UITabBarItem *item1 = [[UITabBarItem alloc] initWithTitle:#"Movies" image:[UIImage imageNamed:#"MoviesTAB.png"] tag:1];
[firstVC setTabBarItem:item1];
UITabBarItem *item2 = [[UITabBarItem alloc] initWithTitle:#"Music" image:[UIImage imageNamed:#"musicTAB.png"] tag:2];
[seconfVC setTabBarItem:item2];
tabController.tabBar.translucent = NO;
tabController.tabBar.barStyle = UIBarStyleBlack;
tabBarController.tintColor = [UIColor whiteColor];
self.window.rootViewController = tabController;
return YES;
}
Best way is use storyboard and there just have one initial UIViewController and from that make segue to UITabBarViewController.
http://youtu.be/a_DCTSTv1Mw
If you want to make it through xib make a UITabBarViewController and add viewControllers to the array of object of that UITabBarViewController's object.
Sample code :
NSMutableArray *arrViewControllers = [[NSMutableArray alloc] init];
UIViewController *tabController;
UIImage *tabImage ;
NSString *tabTitle;
for (int i= 0; i < 3; i++) {
switch (i) {
case 0:
tabController = [[ViewController alloc] init];
tabImage = [UIImage imageNamed:#"icon1.png"];
tabTitle = #"Text";
break;
case 1:
tabController = [[ImageDemoViewController alloc] init];
tabImage = [UIImage imageNamed:#"icon2.png"];
tabTitle = #"Image";
break;
case 2:
tabController = [[TableDemoViewController alloc] init];
tabImage = [UIImage imageNamed:#"icon3.png"];
tabTitle = #"Table";
break;
}
// set the image and title using some properties of UIViewController
tabController.tabBarItem.image = tabImage;
tabController.tabBarItem.title = tabTitle;
//add objects to array
[arrViewControllers addObject:tabController];
[tabController release];
}
_baseController = [[UITabBarController alloc] init];
_baseController.viewControllers = arrViewControllers;
[arrViewControllers release];
go to your appDelegate
1.create a viewController for login screen.
LoginViewController *viewController1 = [[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil];
2.create a navigationController with root view your login ViewController.
UINavigationController *nVC = [[UINavigationController alloc] initWithRootViewController:viewController1];
3.make navigationController to root view of window.
self.window.rootViewController = self.nVC;
[self.window makeKeyAndVisible];
Now go to Touch-Up-Inside method of login button in LoginViewController.
1.After validation of password and userId initialise your viewControllers for tabbar and TabbarViewController.
UiViewController ...*yourViewControllers,..,
UITabBarController *YourtabBarController = [[UITabBarController alloc] init];
2.Now add these viewControllers to your tabbarController.
YourtabBarController.viewControllers = #[ YourViewController1,YourViewController2,YourViewController3,......];
3.Finally push this tabbarController to navigationControllere.
[self.navigationController pushViewController:YourtabBarController animated:NO];

Toolbar + Navigation Bar + Segmented Control?

I'm trying to find a way to layout an application that includes a tab bar on the bottom, a navigation bar on the top, and a row of buttons on the navigation bar that switches views (on the first tab).
I've drawn a very rough sketch (sorry!), but I hope it illustrates the intent.
On the bottom, there are two tabs (tab1, and tab2).
When Tab1 is selected, the navigation bar will have 3 buttons that will show different views (tab1_1, tab1_2, tab1_3).
When Tab2 is selected, the navigation bar won't show any buttons, but rather some simple text.
At this point, I have the following scheme in my application delegate's didFinishLaunchingWithOptions:
UIViewController *viewController1 = [[Tab1_ViewController alloc] initWithNibName:#"Tab1_ViewController" bundle:nil];
UIViewController *viewController2 = [[Tab2_ViewController alloc] initWithNibName:#"Tab2_ViewController" bundle:nil];
tab1NavController = [[UINavigationController alloc] initWithRootViewController:viewController1];
tab2NavController = [[UINavigationController alloc] initWithRootViewController:viewController2];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:tab1NavController, tab2NavController, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
I was wondering if I need to redo how I'm doing things in order to achieve the layout as in the picture.
Any help would be appreciated, thank you!
I have done this for my current project...i hope this will help you....
At first take UITabbarController at your first viewController [first sketch you have given]
For your first view use this code....
- (void)viewDidLoad {
[super viewDidLoad];
dashBoardView = [[DashboardViewController alloc] initWithNibName:#"DashboardViewController" bundle:nil];
dashBoardView.title = #"dashBoardView";
UINavigationController *mydashboarController = [[[UINavigationController alloc] initWithRootViewController:dashBoardView] autorelease];
mydashboarController.navigationBar.barStyle = UIBarStyleBlack;
[listOfViewControllers addObject:mydashboarController];
[dashBoardView release];
ordersView = [[OrdersViewController alloc] initWithNibName:#"OrdersViewController" bundle:nil];
ordersView.title = #"ordersView";
UINavigationController *myorderController = [[[UINavigationController alloc] initWithRootViewController:ordersView] autorelease];
myorderController.navigationBar.barStyle = UIBarStyleBlack;
[listOfViewControllers addObject:myorderController];
[ordersView release];
orderList = [[OrderListViewController alloc] initWithNibName:#"OrderListViewController" bundle:nil];
orderList.title = #"orderList";
UINavigationController *myorderListController = [[[UINavigationController alloc] initWithRootViewController:orderList] autorelease];
myorderListController.navigationBar.barStyle = UIBarStyleBlack;
[listOfViewControllers addObject:myorderListController];
[orderList release];
productView = [[ProductViewController alloc] initWithNibName:#"ProductViewController" bundle:nil];
productView.title = #"productView";
UINavigationController *myproductController = [[[UINavigationController alloc] initWithRootViewController:productView] autorelease];
[listOfViewControllers addObject:myproductController];
[productView release];
[self.tabBarController setViewControllers:listOfViewControllers animated:YES];
NSArray *segmentTextContent = [NSArray arrayWithObjects:NSLocalizedString(#"Dashboard", #""),NSLocalizedString(#"Order", #""),
NSLocalizedString(#"Product", #""),NSLocalizedString(#"More", #""),
nil];
UISegmentedControl* segmentedControl = [[UISegmentedControl alloc] initWithItems:segmentTextContent];
segmentedControl.selectedSegmentIndex = 0;
segmentedControl.autoresizingMask = UIViewAutoresizingFlexibleWidth;
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.frame = CGRectMake(0, 0, 400, 40);
[segmentedControl addTarget:self action:#selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
//defaultTintColor = [segmentedControl.tintColor retain]; // keep track of this for later
segmentedControl.tintColor = [UIColor colorWithHue:8.0 saturation:8.0 brightness:8.0 alpha:1.0];
segmentedControl.alpha = 0.8;
self.navigationItem.titleView = segmentedControl;
[segmentedControl release];
}
If it is not clear to you then please knock...

Resources