iOS 9.0 Tabbar hide automatically and viewcontroller disappear in push - ios

I have a TabBarController with 4 Tab. When i push a ViewController from a tab then the tab is hidden automatically and its showing nothing in View. But ViewController contains a tableview with data. I have implemented tableview delegate also.I am not getting tableview delegate logs.
in appdelegate didFinishLaunchingWithOptions()
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.homeScreen = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.rootNav = [[UINavigationController alloc]initWithRootViewController:self.homeScreen];
self.window.rootViewController = self.rootNav;
[self.window makeKeyAndVisible];
Load TabBar here:
myAppDelegate.myTabBarController.selectedIndex = 0;
myAppDelegate.myTabBarController.tabBar.translucent = NO;
myAppDelegate.myTabBarController.tabBar.opaque = YES;
location_select *tab1 = [[location_select alloc] initWithNibName:#"location_select" bundle:nil];
tab1.tabBarItem.image = [UIImage imageNamed:#"Restaurants.png"];
location_select *tab2 = [[location_select alloc] initWithNibName:#"location_select" bundle:nil];
tab2.title = #"Cart";
tab2.tabBarItem.image = [UIImage imageNamed:#"Cart.png"];
Deal_ViewController *tab3 = [[Deal_ViewController alloc] initWithNibName:#"Deal_ViewController" bundle:nil];
tab3.title = #"Deals";
tab3.tabBarItem.image = [UIImage imageNamed:#"Deals.png"];
MoreViewController *tab4 = [[MoreViewController alloc] initWithNibName:#"MoreViewController" bundle:nil];
tab4.title = #"More";
tab4.tabBarItem.image = [UIImage imageNamed:#"More.png"];
myAppDelegate.myTabBarController.viewControllers = [NSArray arrayWithObjects:tab1,tab2,tab3,tab4,nil];
[myAppDelegate.rootNav pushViewController:myAppDelegate.myTabBarController animated:YES];
From Tab 4, i push Profile_ViewController:
Profile_ViewController *vc = [[Profile_ViewController alloc] initWithNibName:#"Profile_ViewController" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:vc animated:YES];
And already i applied there:
myAppDelegate.myTabBarController.hidesBottomBarWhenPushed=NO;
and
[self.tabBarController setHidesBottomBarWhenPushed:NO];
in viewWillAppear of Profile_ViewController. Nothings works. I just see a blank white screen.

location_select *tab1 = [[location_select alloc] initWithNibName:#"location_select" bundle:nil];
tab1.tabBarItem.image = [UIImage imageNamed:#"Restaurants.png"];
location_select *tab2 = [[location_select alloc] initWithNibName:#"location_select" bundle:nil];
tab2.title = #"Cart";
tab2.tabBarItem.image = [UIImage imageNamed:#"Cart.png"];
Deal_ViewController *tab3 = [[Deal_ViewController alloc] initWithNibName:#"Deal_ViewController" bundle:nil];
tab3.title = #"Deals";
tab3.tabBarItem.image = [UIImage imageNamed:#"Deals.png"];
MoreViewController *tab4 = [[MoreViewController alloc] initWithNibName:#"MoreViewController" bundle:nil];
tab4.title = #"More";
tab4.tabBarItem.image = [UIImage imageNamed:#"More.png"];
UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:tab1];
UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:tab2];
UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:tab3];
UINavigationController *nav4 = [[UINavigationController alloc] initWithRootViewController:tab4];
myAppDelegate.myTabBarController.viewControllers = [NSArray arrayWithObjects:nav1,nav2,nav3,nav4,nil];
[myAppDelegate.rootNav pushViewController:myAppDelegate.myTabBarController animated:YES];
and then later on to push your vc to tab 4 you should do
Profile_ViewController *vc = [[Profile_ViewController alloc] initWithNibName:#"Profile_ViewController" bundle:[NSBundle mainBundle]];
[nav4 pushViewController:vc animated:YES];
here is the Solution related to your query which might help you

You might have kept your architecture as follows
Navigation Controller ---> Tab bar Controller --> 4 child View Controllers
You need to do this
Tab bar Controller --> 4 Child controllers(Each of these 4 child View Controller having its own Navigation Controller).

Related

How to achieve SplitView Functionality in Portrait mode in iOS?

I'm trying to implement SplitView functionality in my iOS application, it's working fine only in landscape mode in iPad devices.
If I launch or rotate the application from landscape to portrait mode splitView functionality is collapsing.
How to achieve SplitView functionality in iPhone(portrait and landscape) and iPad(Portrait mode) devices?
Please find my codeenter image description here below code.
- (BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]bounds]];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
ViewController *masterViewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
DetailViewController *detailViewController = [[DetailViewController alloc]initWithNibName:#"DetailViewController"
bundle:nil];
UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
masterViewController.detailViewController = detailViewController;
self.splitViewController = [[CustomSplitViewController alloc]initWithNibName:#"CustomSplitViewController" bundle:nil];
self.splitViewController.viewControllers = #[masterNavigationController, detailNavigationController];
TabBarDetailController *secondVC = [[TabBarDetailController alloc]initWithNibName:#"TabBarDetailController" bundle:nil];
secondVC.tabBarItem.title = #"Second";
ThirdViewController *thirdVC = [[ThirdViewController alloc]initWithNibName:#"ThirdViewController" bundle:nil];
thirdVC.tabBarItem.title = #"Third";
FourthViewController *fourthVC = [[FourthViewController alloc]initWithNibName:#"FourthViewController" bundle:nil];
fourthVC.tabBarItem.title = #"Fourth";
MoreViewController *moreVC = [[MoreViewController alloc]initWithNibName:#"MoreViewController" bundle:nil];
moreVC.tabBarItem.title = #"More";
//make an array containing view controllers
NSArray *viewControllers = [NSArray arrayWithObjects:self.splitViewController,secondVC,thirdVC,fourthVC,moreVC,nil];
[tabBarController setViewControllers:viewControllers];
self.splitViewController.tabBarItem.title = #"HOME";
[self.window addSubview:tabBarController.view];
self.window.rootViewController=tabBarController;
[[self window] makeKeyAndVisible];
return YES;
}
Thanks in advance.

Navigation Bar not showing title

I am unable to get the navigation bar to show the title that I specify. I have tried to change the title in the AppDelegate.m, as well as in the viewDidLoad of my first tab view. I suspect the title is being hidden, but I am unable fix it. Please provide any insight you may have.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
navigationController = [[UINavigationController alloc] initWithNavigationBarClass:[CRGradientNavigationBar class] toolbarClass:nil];
UIColor *firstColor = [UIColor colorWithRed:155.0f/255.0f green:41.0f/255.0f blue:104.0f/255.0f alpha:1.0f];
UIColor *secondColor = [UIColor colorWithRed:215.0f/255.0f green:90.0f/255.0f blue:18.0f/255.0f alpha:1.0f];
NSArray *colors = [NSArray arrayWithObjects:firstColor, secondColor, nil];
[[CRGradientNavigationBar appearance] setBarTintGradientColors:colors];
self.navigationController.title = #"This title is not showing";
[[navigationController navigationBar] setTranslucent:NO];
//create the view controller for the first tab
self.firstViewController = [[FirstViewController alloc] initWithNibName:nil
bundle:NULL];
//create the view controller for the second tab
self.secondViewController = [[SecondViewController alloc] initWithNibName:nil
bundle:NULL];
//create the view controller for the third tab
self.thirdViewController = [[ThirdViewController alloc] initWithNibName:nil
bundle:NULL];
//create the view controller for the fourth tab
self.fourthViewController = [[FourthViewController alloc] initWithNibName:nil
bundle:NULL];
//create an array of all view controllers that will represent the tab at the bottom
NSArray *myViewControllers = [[NSArray alloc] initWithObjects:
self.firstViewController,
self.secondViewController, self.thirdViewController, self.fourthViewController, nil];
//initialize the tab bar controller
self.tabBarController = [[MainUITabBarController alloc] init];
//set the view controllers for the tab bar controller
[self.tabBarController setViewControllers:myViewControllers];
[navigationController setViewControllers:#[self.tabBarController]];
[self.window setRootViewController:navigationController];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
The relationship of your view controllers isn't right.
The root view controller of your app should be the TabBarController.
Each of the items should have it's own Navigation Controller.
The title of each ViewController can be set in viewDidLoad() with self.title = "....
I've been able to set titles in the delegate as follows:
1.) Create view controllers
2.) Set those titles
3.) Then create UINavigationControllers and assign view controllers there
self.firstViewController = [[FirstViewController alloc] initWithNibName:nil bundle:nil];
self.secondViewController = [[SecondViewController alloc] initWithNibName:nil bundle:nil];
self.thirdViewController = [[ThirdViewController alloc] initWithNibName:nil bundle:nil];
self.fourthViewController = [[FourthViewController alloc] initWithNibName:nil bundle:nil];
[self.firstViewController setTitle:#"First"];
[self.secondViewController setTitle:#"Second"];
[self.thirdViewController setTitle:#"Third"];
[self.fourthViewController setTitle:#"Fourth"];
UINavigationController *controller1 = [[UINavigationController alloc] initWithRootViewController:self.firstViewController];
UINavigationController *controller2 = [[UINavigationController alloc] initWithRootViewController:self.secondViewController];
UINavigationController *controller3 = [[UINavigationController alloc] initWithRootViewController:self.thirdViewController];
UINavigationController *controller4 = [[UINavigationController alloc] initWithRootViewController:self.fourthViewController];
NSArray *viewControllers = [NSArray arrayWithObjects:controller1, controller2, controller3, controller4, nil];

How to show tab bar in all views

Following is my code and it is showing tab bar only on given 2 tab bar items but it is not showing tab bar in other views.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.startQuizViewController = [[StartQuizViewController alloc] initWithNibName:nil bundle:nil];
self.scoreViewController = [[ScoreViewController alloc] initWithNibName:nil bundle:nil];
self.startQuizViewController.title = #"QUIZ";
self.scoreViewController.title = #"SCORES";
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:self.startQuizViewController,self.scoreViewController,nil];
_navigationController=[[UINavigationController alloc]initWithRootViewController:self.tabBarController];
[self.window addSubview:self.navigationController.view];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
code in written in didFinishLaunchingWithOptions in AppDelegate.m.
change this part:
_navigationController=[[UINavigationController alloc]initWithRootViewController:self.tabBarController];
[self.window addSubview:self.navigationController.view];
self.window.rootViewController = self.navigationController;
to this:
self.window.rootViewController = self.tabBarController;
you cannot have tabbarcontroller inside a navigation controller. so just remove navigation controller and set tab bar controller as root view controller
edit:
self.startQuizViewController = [[StartQuizViewController alloc] initWithNibName:nil bundle:nil];
self.scoreViewController = [[ScoreViewController alloc] initWithNibName:nil bundle:nil];
self.startQuizViewController.title = #"QUIZ";
self.scoreViewController.title = #"SCORES";
self.tabBarController = [[UITabBarController alloc] init];
UINavigationController * nav1 = [[UINavigationController alloc] initWithRootViewController:self.startQuizViewController];
UINavigationController * nav2 = [[UINavigationController alloc] initWithRootViewController:self.scoreViewController];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:nav1, nav2, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
that's it. you can now push view controller inside those controller and can have the tab bar always there.
Use this
UIViewController *viewController1, *viewController2;
viewController1 = [[UIViewController alloc] initWithNibName:#"FirstViewController" bundle:nil] ;
UINavigationController *navigationcontroller = [[UINavigationController alloc] initWithRootViewController:viewController1] ;
viewController2 = [[UIViewController alloc] initWithNibName:#"SecondViewController" bundle:nil] ;
UINavigationController *navigationcontroller2 = [[UINavigationController alloc] initWithRootViewController:viewController2] ;
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navigationcontroller, navigationcontroller2, nil];
and finally
self.window.rootViewController = self.tabBarController;
This way you have seperate navigation controllers for both tabbar controller.

Blank screen while adding subview in arc

I want a tabbarcontroller which should be inside a navigationcontroller. And i need to add it as the subview of my master page. Without ARC this code working fine. But a black screen appear when it is in ARC. help me please.
UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.delegate = self;
RestaurantListingClass *restList = [[RestaurantListingClass alloc]initWithNibName:#"RestaurantListingClass" bundle:Nil];
UITabBarItem *placeTab = [[UITabBarItem alloc] initWithTitle:#"Places" image:nil tag:1];
restList.tabBarItem = placeTab;
ReOrderVC *reorder=[[ReOrderVC alloc]initWithNibName:#"ReOrderVC" bundle:Nil];
UITabBarItem *reorderTab = [[UITabBarItem alloc] initWithTitle:#"Re-order" image:nil tag:1];
reorder.tabBarItem=reorderTab;
tabBarController.viewControllers=[NSArray arrayWithObjects:restList,reorder, nil];
UINavigationController *navcontroller =[[UINavigationController alloc]initWithRootViewController:tabBarController];
DesignElementsClass *DEClass = [[DesignElementsClass alloc] init];
[DEClass setImageForsubNAvBar:navcontroller.navigationBar];
[DEClass setImageForsubTabBar:tabBarController.tabBar];
navcontroller.view.frame = view.bounds;
[self addChildViewController:navcontroller];
[self.view addSubview:navcontroller.view];
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"Main_iPhone" bundle:[NSBundle mainBundle]];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
ViewOne *firstView = [storyBoard instantiateViewControllerWithIdentifier:#"ViewControllerOne"];
ViewTwo *secondView = [storyBoard instantiateViewControllerWithIdentifier:#"ViewControllerTwo"];
UITabBarItem *placeTab = [[UITabBarItem alloc] initWithTitle:#"Places" image:nil tag:1];
firstView.tabBarItem = placeTab;
UITabBarItem *reorderTab = [[UITabBarItem alloc] initWithTitle:#"Re-order" image:nil tag:1];
secondView.tabBarItem=reorderTab;
tabBarController.viewControllers=[NSArray arrayWithObjects:firstView,secondView, nil];
UINavigationController *navcontroller =[[UINavigationController alloc]initWithRootViewController:tabBarController];
[self addChildViewController:navcontroller];
[self.view addSubview:navcontroller.view];

How can we implement a common tabbar for all views in IOS?

I am new to IOS. In my app's home, there are 3 tabs and 4 buttons(using navigation controllers). I created a tabbarcontroller inside appdelegate.m as follows:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
//Initializing the view controllers
UIViewController *disController1 = [[DisController1 alloc]initWithNibName:#"DisController1" bundle:nil];
UIViewController *viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
UIViewController *wishlistController = [[Wishlist alloc]initWithNibName:#"Wishlist" bundle:nil];
UIViewController *helpController = [[HelpController alloc]initWithNibName:#"HelpController" bundle:nil];
UIViewController *disController2 = [[DisController1 alloc]initWithNibName:#"DisController2" bundle:nil];
NSMutableArray *viewControllersArray = [[NSMutableArray alloc]init];
[viewControllersArray addObject:disController1];
[viewControllersArray addObject:viewController];
[viewControllersArray addObject:wishlistController];
[viewControllersArray addObject:helpController];
[viewControllersArray addObject:disController2];
//Initializing the tab bar controller
UIImage *img = [UIImage imageNamed:#"SES_tab bar"];
CGSize newSize = CGSizeMake(SCRN_WIDTH, TABHEIGHT);
Common *common = [[Common alloc]init];
UIImage *newImage = [common imageResize:img andResizeTo:newSize];
[common setTabBarColorandImage:newImage];
tabController = [[UITabBarController alloc]init];
tabController.viewControllers = [NSArray arrayWithObjects:disController1, viewController,wishlistController,helpController,disController2 ,nil];
tabController.selectedIndex = 1;
UITabBarItem *firstTab = [[tabController.tabBar items]objectAtIndex:0];
UITabBarItem *lastTab = [[tabController.tabBar items]objectAtIndex:4];
[firstTab setEnabled:NO];
[lastTab setEnabled:NO];
UINavigationController *navCtrl = [[UINavigationController alloc]initWithRootViewController:tabController];
//navCtrl.navigationBarHidden = NO;
//[navCtrl.navigationBar setBackgroundImage:img forBarMetrics:UIBarMetricsDefault];
[navCtrl.navigationBar setBarStyle:UIBarStyleBlackTranslucent ];
[navCtrl.navigationBar.topItem setTitle:#"Home"];
[self.window addSubview:tabController.view];
self.window.rootViewController = navCtrl;
[self.window makeKeyAndVisible];
return YES;
TabBar works fine for my home page.But my problem is when i clicks on a button, Tab bar doesn't appear in the new view. How can I implement that?
You should create UINavigationControllers for each of your tabs. Set each view controller in your current array as the root view controller of each of those navigation controllers.
EDIT:
UIViewController *disController1 = [[DisController1 alloc]initWithNibName:#"DisController1" bundle:nil];
UIViewController *viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
UIViewController *wishlistController = [[Wishlist alloc]initWithNibName:#"Wishlist" bundle:nil];
UIViewController *helpController = [[HelpController alloc]initWithNibName:#"HelpController" bundle:nil];
UIViewController *disController2 = [[DisController1 alloc]initWithNibName:#"DisController2" bundle:nil];
UINavigationController *navController1 = [[UINavigationController alloc] initWithRootViewController:disController1];
//etc. for each of the view controllers that you have allocated.
NSMutableArray *viewControllersArray = [[NSMutableArray alloc]init];
[viewControllersArray addObject:navController1];
[viewControllersArray addObject:navController2];
[viewControllersArray addObject:navController3];
[viewControllersArray addObject:navController4];
[viewControllersArray addObject:navController5];

Resources