I am changing UITabBarItem title after the user changes his language preferences in the app settings. The problem is that the whole item disappears for a while after this change is made and then appears again with the new title.
In AppDelegate I am initializing UITabBarController:
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.delegate = self;
BFNCategoriesTableViewController *shopViewController = [[BFNCategoriesTableViewController alloc] init];
UINavigationController *shopNavigationController = [[UINavigationController alloc] initWithRootViewController:shopViewController];
shopNavigationController.tabBarItem = [[UITabBarItem alloc] initWithTitle:BFNLocalizedString(kTranslationShop) image:[UIImage imageNamed:#"TabBarShopUnselected"] selectedImage:[UIImage imageNamed:#"TabBarShopSelected"]];
self.tabBarController.viewControllers = #[offersNavigationController,
shopNavigationController,
//wishlistNavigationController,
cartNavigationController,
moreNavigationController];
Then after the translation is downloaded I just set different title like this:
navigationController.title = BFNLocalizedString(kTranslationCart);
Do you have an idea why this happens and eventually how to ovecome this issue?
Thanks.
Firstly, I can't understand regarding code above, how tabBarController is connected with UINavigationController.
You should
self.tabBarController.viewControllers = [NSArray arrayWithObject: shopViewController];
UINavigationController *shopNavigationController = [[UINavigationController alloc] initWithRootViewController: self.tabBarController ];
UINavigationController doesn't have a property is tabBarItem.
Following that:
shopViewController.title = = BFNLocalizedString(kTranslationCart);
It changes a title is on top of navController and title of tabBar as well.
Another way, It can change a tabBarTitle directly.
UITabBar *tabBar = self.tabBarController.tabBar;
UITabBarItem * itemBar = [ [UITabBarItem alloc] initWithTitle:BFNLocalizedString(kTranslationCart)
image:(UIImage *)image // your image
selectedImage:(UIImage *)selectedImage]; // highlighted image
[tabBar setItems:[NSArray arrayWithObject:itemBar
animated:YES ];
I think a first way is enough it must certainly work.
Related
I have a tab bar controller with three tabs that I set programmatically. The two first ones are just UIViewController but the third one is an UISplitViewController that I get from another storyboard. Everything works great but when I'm on portrait mode and show the master view, this one is showed on top of the tab bar. I would like keep showing the full tab bar.
This also generate problems when trying to show an UIAlertController from an item bar button in the master view (this button doesn't exist in the image) as the popover is showed behind the master view.
Does anyone know how can I workaround this?
The way I set them programmatically is this (in case it may help):
UIViewController *view1 = [[UIStoryboard storyboardWithName:#"Main" bundle:nil] instantiateViewControllerWithIdentifier:#"FirstView"];
UIViewController *view2 = [[UIStoryboard storyboardWithName:#"Main" bundle:nil] instantiateViewControllerWithIdentifier:#"SecondView"];
UIViewController *view3 = [[UIStoryboard storyboardWithName:#"StoryboardSplit" bundle:nil] instantiateViewControllerWithIdentifier:#"MySplitView"];
UISplitViewController *splitViewController = (UISplitViewController *)view3;
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
navigationController.topViewController.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem;
splitViewController.delegate = self;
NSMutableArray *tabViewControllers = [[NSMutableArray alloc] init];
[tabViewControllers addObject:view1];
[tabViewControllers addObject:view2];
[tabViewControllers addObject:splitViewController];
[self setViewControllers:tabViewControllers];
view1.tabBarItem =
[[UITabBarItem alloc] initWithTitle:#"view1"
image:[UIImage imageNamed:#"view1"]
tag:1];
view2.tabBarItem =
[[UITabBarItem alloc] initWithTitle:#"view2"
image:[UIImage imageNamed:#"view2"]
tag:2];
view3.tabBarItem =
[[UITabBarItem alloc] initWithTitle:#"view3"
image:[UIImage imageNamed:#"view3"]
tag:3];
Try importing QuartzCore, then setting TabBarController.tabBar.layer.zposition = 1. Of course replacing the necessaries like tabBar with the name of your tab bar and so on. This is works in Swift however through your own initiative you can work this into Obj-C
I have a PPRevealSideViewController and when is being called appears the status bar on top of view.
I initialize it in appDelegate.m like this:
MainViewController *main = [[MainViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:main];
_revealSideViewController = [[RootViewController alloc] initWithRootViewController:nav];
_revealSideViewController.delegate = self;
self.window.rootViewController = _revealSideViewController;
[self.window makeKeyAndVisible];
Could anyone tell me how can I make this disappear, or make it the color of background?
Finally I found the answer.
You have two options (fading is set as default). PPRevealSideOptionsiOS7StatusBarFading and PPRevealSideOptionsiOS7StatusBarMoving.
And you can change the color of status bar like this:
[self.revealSideViewController setFakeiOS7StatusBarColor:<#(UIColor *)#>];
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.
My IOS app has a login sequence that cannot be modified, once the sequence is complete I do the following in the app delegate
- (UIViewController*)newRootViewController {
NViewController *nView = [[NViewController alloc]
initWithNibName:#"NViewController"
bundle:nil];
UINavigationController *navVC = [[UINavigationController alloc] initWithRootViewController:nView];
[nView release];
return navVC;
}
Once in nView is it possible to add a tab bar controller or how can I replace nView with a tab bar controller.
You can create a UITabBarController then add your NViewController and other controllers to the tab bar.
NViewController *nView = [[NViewController alloc]
initWithNibName:#"NViewController"
bundle:nil];
//Create my tab bar
UITabBarController* myTabController = [[UITabBarController alloc]init];
//Add my tabs
NSArray* tabs = [[NSArray alloc]initWithObjects:nView, nil];
[myTabController setViewControllers:tabs];
Just created a new project and I have 4 view controllers which I add to UINavigationController like this:
WatchViewController *first = [[WatchViewController alloc] init];
BetViewController *second = [[BetViewController alloc] init];
Settings *third = [[Settings alloc] init];
Account *forth = [[Account alloc] init];
UINavigationController *navFirst = [[UINavigationController alloc]initWithRootViewController:first];
UINavigationController *navSecond = [[UINavigationController alloc]initWithRootViewController:second];
UINavigationController *navThird = [[UINavigationController alloc]initWithRootViewController:third];
UINavigationController *navForth = [[UINavigationController alloc]initWithRootViewController:forth];
Load them into an array:
NSArray *viewArray = [[NSArray alloc] initWithObjects:navFirst, navSecond, navThird, navForth, nil];
Load the tab bar and window:
self.tabController = [[UITabBarController alloc] init];
[self.tabController setViewControllers:viewArray animated:YES];
[self.window setRootViewController:self.tabController];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
All the view are just standard views. When I try and run the app it responds with :
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing a navigation controller is not supported'
I can't figure out what I've missed. Any help?
Don't create 4 navigation controllers. Controllers that are needed to navigate through should be assigned to viewControllers property in UINavigationController via setViewControllers:animated: method.
You should create 1 NavigationController and add array of 4 UIViewControllers.
A very good example is given here: example and don't forget to look here UINavigationClass
Try this one:
WatchViewController *first = [[WatchViewController alloc] initWithNibName:#"WatchViewController" bundle:Nil];
BetViewController *second = [[BetViewController alloc] initWithNibName:#"BetViewController" bundle:Nil];
Settings *third = [[Settings alloc] initWithNibName:#"Settings" bundle:Nil];
Account *forth = [[Account alloc] initWithNibName:#"Account" bundle:Nil];
/*Your View Navigation Stuff and your viewArray*/
self.tabController.viewControllers = viewArray;
Why don't you try UINavigationController inside UITabBarController by setting controllers in xib. It worked for me.
Sorry, I had annoyingly subclassed UINavigationController instead of UIViewController. I hadn't picked up on it because if I didn't use the NavControllers the App would run fine, add the nav controllers and it broke. :(