UITabbar disappears when i push view controller - ios

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 !

Related

Why is view of UINavigationController root controller smaller than nav controller

I am trying to create a transparent UINavigationBar and here is what I do:
First, I have a navVC and a general VC as root VC in my code.
SNLoginViewController *loginVC = [[SNLoginViewController alloc] init];
SNLoginNavController *loginNavVC = [[SNLoginNavController alloc] initWithRootViewController:loginVC];
[self presentViewController:loginNavVC animated:YES completion:nil];
I didn't override the init method of SNLoginViewController.
And here is the implementation of initWithRootViewController::
- (instancetype)initWithRootViewController:(UIViewController *)rootViewController {
self = [super initWithRootViewController:rootViewController];
if (self) {
UIImage *bgImage = [UIImage imageNamed:#"bg"];
UIImageView *bgImageView = [[UIImageView alloc] initWithImage:bgImage];
bgImageView.frame = [UIScreen mainScreen].bounds;
[self.view insertSubview:bgImageView atIndex:0];
[self.navigationBar setBackgroundImage:[UIImage imageNamed:#"transparent"]//transparent is a transparent png
forBarMetrics:UIBarMetricsCompact];
self.navigationBar.shadowImage = [UIImage imageNamed:#"transparent"];
self.navigationBar.barStyle = UIBarStyleBlackTranslucent;
[self.navigationBar setTitleTextAttributes:#{NSForegroundColorAttributeName:[UIColor whiteColor], NSFontAttributeName: [UIFont systemFontOfSize:18]}];
self.navigationBar.clipsToBounds = YES;
}
return self;
}
Using these codes (setBackgroundImage:forBarMetrics:) I should have been able to make the navigation bar transparent but something went wrong. The major problem is that somehow the frame of loginVC is smaller than loginNavVC.
(source: zybuluo.com)
In the figure above the selected view is of loginVC and the one on the left is of loginNavVc. loginVC is smaller than loginNavVc.
But in viewDidLoad of loginVC I print the selected view, its frame is (0 0; 320 568) but when I print its description in view hierarchy (same address in memory), its frame is (0 64; 320 504). Why would this happen? How to make it full screen(not full screen like games, status bar should still be visiable)?
Add this before presenting your navigation controller.
[self.loginNavVC.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
self. loginNavVC.navigationBar.translucent = YES;

UINavigationView can not pop, Only navigation pop animation, UIViewController not changed

I use the custom UINavigationController as a rootViewController. The UINavigationController's first viewController is a UITabBarController. Each UITabBarController is a custom UINavigationConller.When the tabBarController is shown, I hide the rootViewController's navigationBar.
Init the UITabbarController
+(RDVTabBarController *)tabBarControllertWithIndex:(NSUInteger)index
{
UIViewController *goodsHomeController = [[ESGoodsHomeViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *goodsHomeNavi = [[ESNavigationController alloc]
initWithRootViewController:goodsHomeController];
........
ESTabBarController *tabBarController = [[ESTabBarController alloc] init]; //对status bar 能定制
[tabBarController setViewControllers:#[goodsHomeNavi,categoryNavi,shoppingCarNavi,userCenterNavi]];
return tabBarController;
}
Set it to a navigationController
self.tabController = [UIHelper tabBarControllertWithIndex:0];
self.tableController.delegate = self;
UINavigationController *tabBarNavigation = [UIHelper navigationControllerViewController:self.tableController];
tabBarNavigation.navigationBarHidden = TRUE;
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
self.window.rootViewController = tabBarNavigation;
In the baseViewController ,I customise the back item in the navigationBar
- (void)setCustomNavigationBackButton
{
UIImage *backBtn = [UIImage imageNamed:#"bar_back"];
UIImage *backDownBtn = [UIImage imageNamed:#"bar_back_down"];
backBtn = [backBtn imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
backDownBtn = [backDownBtn imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
self.navigationItem.backBarButtonItem.title=#"";
self.navigationController.navigationBar.backIndicatorImage = backBtn;
self.navigationController.navigationBar.backIndicatorTransitionMaskImage = backBtn;
}
In some cases, I change the viewControllers of a navigationController when I push a viewController after the push animation is finished. I use a navigationController+block
- (void)popToViewController:(UIViewController *)viewController animated:(BOOL)animated onCompletion:(void(^)(void))completion
{
[CATransaction begin];
[CATransaction setCompletionBlock:completion];
[self popToViewController:viewController animated:animated];
[CATransaction commit];
}
After finished the block is executed
[UIHelper viewController:self pushViewController:orderDetail completion:^{
NSMutableArray *afterController = [NSMutableArray array]; //将本页面删除
NSArray *viewController = self.navigationController.viewControllers;
[viewController enumerateObjectsUsingBlock:^(UIViewController *obj, NSUInteger idx, BOOL *stop) {
if (![obj isKindOfClass:[ESPurchaseViewController class]]) {
[afterController addObject:obj];
}
}];
self.navigationController.viewControllers = afterController;
}];
In some push, when I come from the UITabBarController push to a secondViewController, I hide navigationBar and show the root navigationBar.
+(void)tabController:(UIViewController *)tabController pushSubController:(UIViewController *)subViewController
{
[tabController.rdv_tabBarController.navigationController pushViewController:subViewController animated:YES];
tabController.rdv_tabBarController.navigationController.navigationBarHidden = FALSE;
}
I can not find the reason why the navigation can not pop. That does not always happen.
Any wrong basic knowledge of iOS about the UINavigationContller,UITabBarController,UIViewController for me to know?
Thank you!
if i think your need is First MainNavigationViewController then tabbar Controller with it and each tab bar's view controller is also having its own nvaigation controller then it will work fine..
listViewController = [[CBListViewController alloc] initWithStyle:UITableViewStylePlain];
bookmarkController = [[CBBookmarksViewController alloc] initWithStyle:UITableViewStylePlain];
settingsController = [[CBActivityViewController alloc] init ];
searchController = [[CBSearchViewController alloc] initWithNibName:#"CBSearchViewController" bundle:nil];
nearbyController = [[CBViewOnMapViewController alloc] init ];
UINavigationController *bNavigationController = [[UINavigationController alloc] initWithRootViewController:bookmarkController];
self.navigationControllerForBookmark = bNavigationController;
UITabBarItem *tab2=[[UITabBarItem alloc]init];
tab2.image = [[UIImage imageNamed:#"bookmark.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tab2.selectedImage = [[UIImage imageNamed:#"bookmark_active.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tab2.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);
navigationControllerForBookmark.tabBarItem = tab2;
UINavigationController *cNavigationController = [[UINavigationController alloc] initWithRootViewController:settingsController];
self.navigationControllerForSettings = cNavigationController;
UITabBarItem *tab3=[[UITabBarItem alloc]init];
tab3.image = [[UIImage imageNamed:#"activites.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tab3.selectedImage = [[UIImage imageNamed:#"activites_active.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tab3.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);
navigationControllerForSettings.tabBarItem = tab3;
UINavigationController *dNavigationController = [[UINavigationController alloc] initWithRootViewController:searchController];
self.navigationControllerForSearch = dNavigationController;
UITabBarItem *tab4=[[UITabBarItem alloc]init];
tab4.image = [[UIImage imageNamed:#"Search.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tab4.selectedImage = [[UIImage imageNamed:#"Search_active.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
self.navigationController.tabBarItem = tab4;
tab4.imageInsets=UIEdgeInsetsMake(5, 0, -5, 0);
navigationControllerForSearch.tabBarItem=tab4;
UINavigationController *eNavigationController = [[UINavigationController alloc] initWithRootViewController:nearbyController];
self.navigationControllerForNearby = eNavigationController;
UITabBarItem *tab5=[[UITabBarItem alloc]init];
tab5.image = [[UIImage imageNamed:#"nearby.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tab5.selectedImage = [[UIImage imageNamed:#"nearby_active.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
self.navigationController.tabBarItem = tab5;
tab5.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);
navigationControllerForNearby.tabBarItem = tab5;
[navigationControllerForNearby.navigationBar setBackgroundImage:[UIImage imageNamed:#"headerBar"] forBarMetrics:UIBarMetricsDefault];
UINavigationController *aNavigationController = [[UINavigationController alloc] initWithRootViewController:listViewController];
self.navigationController = aNavigationController;
UITabBarItem *tab1=[[UITabBarItem alloc]init];
tab1.image = [[UIImage imageNamed:#"review.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tab1.selectedImage = [[UIImage imageNamed:#"review_active.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tab1.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);
navigationController.tabBarItem = tab1;
[[UITabBar appearance] setBarTintColor:GRAY_COLOR];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navigationController, navigationControllerForNearby, navigationControllerForSearch, navigationControllerForBookmark, navigationControllerForSettings, nil];
self.window.rootViewController = self.tabBarController;
check if this solves your problem sir.

UITabBarController initially highlights all tab bar item images

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];

UINavigation with UITabbar not working

I'm trying to change views within an app I am editing the code for. But the navigation bar doesn't seem to update in specific instances when presenting a new viewcontroller. Right now the behavior looks like this:
I navigate to a tableviewcontroller by clicking on a tab in the tabbar,
then I navigate to a viewcontroller from this tableviewcontroller using:
settingsController = [SettingsController create];
[self.navigationController pushViewController: settingsController animated: YES];
which I believe calls this code:
+(id)create
{
SettingsController*settings = [[SettingsController alloc] init];
NSBundle*bundle = [NSBundle bundleForClass: [SettingsController class]];
[bundle loadNibNamed: #"SettingsController" owner: settings options: NULL];
settings.view.frame = CGRectMake(0, 0, 320, 411);
settings.title = #"Settings";
return settings;
}
Then from there I navigate to another view controller using:
SearchViewController*searchView;
searchView = [[SearchViewController alloc] initWithNibName:#"SearchView" bundle: [NSBundle mainBundle]];
[self presentViewController:searchView animated:YES completion:nil];
and this is where the behavior starts getting buggy, the navigation bar doesnt update to the change in the view controller. I didn't write this code but it has been giving me a headache trying to clean it up.
If you are using a navigationController then you shouldn't call
[self presentViewController:searchView animated:YES completion:nil];.
You should use
[self.navigationController pushViewController:searchView animated:YES];
Also, it would be better to use the standard in-built function to initialize a new view controller.
SettingsController*settings = [[SettingsController alloc] initWithNibName:#"SettingsController" bundle:nil];
[self.navigationController pushViewController:settings animated:YES];
and then use the default method in the view controller.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = #"Settings";
//other view changes.
}
return self;
}
See this example for the way of initializing tabbarcontroller with navigation controller
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIViewController *viewController1, *viewController2,*viewController3;
viewController1 = [[ViewController alloc] init];
viewController2 = [[FormStatusViewController alloc] initWithNibName:#"FormStatusViewController" bundle:nil];
viewController3 = [[DocumentsViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewController1];
UINavigationController *nav1 =[[UINavigationController alloc] initWithRootViewController:viewController2];
UINavigationController *nav2 =[[UINavigationController alloc] initWithRootViewController:viewController3];
nav.navigationBarHidden=YES;
nav1.navigationBarHidden=YES;
nav2.navigationBarHidden=YES;
NSArray *viewsArray = [[NSArray alloc] initWithObjects:nav,nav1,nav2, nil];
self.formTabBar= [[UITabBarController alloc] init];
[self.formTabBar setViewControllers:viewsArray];
UITabBar *tabBar = self.formTabBar.tabBar;
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];
UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:2];
tabBarItem1.title = #"FORM";
tabBarItem2.title = #"STATUS";
tabBarItem3.title = #"DOCUMENTS";
UIImage *tabBackground = [[UIImage imageNamed:#"tab_bg.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UITabBar appearance] setBackgroundImage:tabBackground];
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 7) {
[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:#"form.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"form_h.png"]];
[tabBarItem2 setFinishedSelectedImage:[UIImage imageNamed:#"status.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"status_h.png"]];
[tabBarItem3 setFinishedSelectedImage:[UIImage imageNamed:#"documents.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"documents_h.png"]];
} else {
tabBarItem1.selectedImage = [[UIImage imageNamed:#"form_h.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabBarItem1.image = [[UIImage imageNamed:#"form.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabBarItem2.selectedImage = [[UIImage imageNamed:#"status_h.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabBarItem2.image = [[UIImage imageNamed:#"status.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabBarItem3.selectedImage = [[UIImage imageNamed:#"documents_h.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabBarItem3.image = [[UIImage imageNamed:#"documents.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
}
[[UITabBar appearance] setSelectionIndicatorImage:
[UIImage imageNamed:#"tab_select_indicator.png"]];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
nil] forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
nil] forState:UIControlStateHighlighted];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = self.formTabBar;
[self.window makeKeyAndVisible];
return YES;
}
Now in your view controller suppose the firstviewcontroller in first tab you want to navigate to another view controller in that tab then use below code
SearchViewcontroller *searchView =[[SearchViewcontroller alloc]init];
[self.navigationController pushViewController:searchView animated:YES];

Customizing appearance of tabBarItems in a TabBArController

In my application, I am using a UITabBarController. However, i need to customise the appearance of my UITabBarItems.
At present, my screen looks like this:
I would like to increase the distance between the tabs, and the middle tab has bigger text, due to which the tab looks very crowded. Also, i would like to add a separator between the tabs.
Here's the code:
customerCareNavController = [[UINavigationController alloc] initWithRootViewController:custCareVC];
customerCareNavController.title = #"Inquiry";
purchaseOrderNavController = [[UINavigationController alloc] initWithRootViewController:POController];
purchaseOrderNavController.title = #"Purchase Order";
accAndContactsNavController = [[UINavigationController alloc] initWithRootViewController:accAndContactsController];
accAndContactsNavController.title = #"Accounts And Contacts";
tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects:customerCareNavController,accAndContactsNavController,purchaseOrderNavController, nil];
[(UITabBarItem*)[tabBarController.tabBar.items objectAtIndex:0] setImage:[UIImage imageNamed:#"Customer_Service.png"]];
[(UITabBarItem*)[tabBarController.tabBar.items objectAtIndex:1] setImage:[UIImage imageNamed:#"Acc_Cont.png"]];
[(UITabBarItem*)[tabBarController.tabBar.items objectAtIndex:2] setImage:[UIImage imageNamed:#"PO.png"]];
Set tabBarItem such like
UITabBarItem* ClientSupportTabBarItem = [[UITabBarItem alloc] init];
[ClientSupportTabBarItem setFinishedSelectedImage: [UIImage imageNamed: #"btnTabItem-active.png"] withFinishedUnselectedImage: [UIImage imageNamed: #"btnTabItemNormal.png"]];
ClientSupportTabBarItem.title = #"Inquiry";
[customerCareNavController setTabBarItem: ClientSupportTabBarItem];

Resources