The tabBarController is not displayed - iphone

i want to make tabbarcontroller programatically. The tabBarController is not displayed in the page. can anyone tell that whts going wrong.and can we make more than one tabbarcontroller in an application
ViewController.m
- (void)viewDidLoad
{
report=[[UIViewController alloc]initWithNibName:#"ViewController" bundle:nil];
View1 *template=[[View1 alloc]initWithNibName:#"View1" bundle:nil];
View2 *acc=[[View2 alloc]initWithNibName:#"View2" bundle:nil];
View3 *four=[[View3 alloc]initWithNibName:#"View3" bundle:nil];
View4 *five=[[View4 alloc]initWithNibName:#"View4" bundle:nil];
nav1=[[UINavigationController alloc]initWithRootViewController:report];
nav2=[[UINavigationController alloc]initWithRootViewController:template];
nav3=[[UINavigationController alloc]initWithRootViewController: acc];
nav4=[[UINavigationController alloc]initWithRootViewController:four];
nav5=[[UINavigationController alloc]initWithRootViewController:five];
UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:#"Title" image:[UIImage imageNamed:#"singleicon.png"] tag:0];
UITabBarItem *item1 = [[UITabBarItem alloc] initWithTitle:#"Reports" image:[UIImage imageNamed:#"doubleicon.png"] tag:1];
UITabBarItem *item2 = [[UITabBarItem alloc] initWithTitle:#" New " image:[UIImage imageNamed:#"clockicon.png"] tag:2];
UITabBarItem *item3=[[UITabBarItem alloc]initWithTitle:#"four" image:[UIImage imageNamed:#"dependenticon.png"] tag:3];
UITabBarItem *item4=[[UITabBarItem alloc]initWithTitle:#"five" image:[UIImage imageNamed:#"toolicon.png"] tag:4];
nav1.tabBarItem = item;
nav2.tabBarItem = item1;
nav3.tabBarItem = item2;
nav4.tabBarItem=item3;
nav5.tabBarItem=item4;
//[item1 setBadge:#"25"];
self.tabBarController=[[UITabBarController alloc]init];
[self.tabBarController setViewControllers:[NSArray arrayWithObjects:nav1,nav2,nav3,nav4,nav5,nil]];
self.report = self.tabBarController;
// [self.report makeKeyAndVisible];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

Use below code:
self.tabBarController.viewControllers = [NSArray arrayWithObjects:nav1,nav2,nav3,nav4,nav5,nil]];
self.window.rootViewController = self.tabBarController;
UPDATE:
also for Hide and Show the UITabBar then use bellow code ..
just put this methods in AppDelegate.m file and when you want to hide tabbar at that time just create AppDelegate object and call bellow hideTabBar method
- (void) hideTabBar:(UITabBarController *) tabbarcontroller {
int height = 480;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
for(UIView *view in tabbarcontroller.view.subviews) {
if([view isKindOfClass:[UITabBar class]]) {
[view setFrame:CGRectMake(view.frame.origin.x, height, view.frame.size.width, view.frame.size.height)];
}
else {
[view setFrame:CGRectMake(view.frame.origin.x,view.frame.origin.y, 320, 436)];
}
}
[UIView commitAnimations];
}
- (void) showTabBar:(UITabBarController *) tabbarcontroller {
int height = 436;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
for(UIView *view in tabbarcontroller.view.subviews) {
if([view isKindOfClass:[UITabBar class]]) {
[view setFrame:CGRectMake(view.frame.origin.x, height, view.frame.size.width, view.frame.size.height)];
}
else {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, height)];
}
}
[UIView commitAnimations];
}

put all the coding in the action of the button and push the tabBarController like that:-
[self.navigationController pushViewController:tabBarController animated:YES];

If you want to add UITabBarController programmatically, then you need to add your tabbarcontroller to your ViewController. you need to use this line,
[self.view addSubview:self.tabBarController.view];

You need to add tabBarController in view you have missed the one line

i just did this
[self.navigationController pushViewController:tabBarController animated:YES];

Related

How to load a tabbar controller xib using navigation controller

I am new to ios, I had a problem with tabbar controller. I am using two tab bar controller in my project.One is loaded at app lunch and it is working good.I want to load another at didselect row.How to do this. I have done many experiments but nothing works.
-(void) hidetabbar {
[UIView animateWithDuration:0.5
animations:^{
for(UIView *view in tabBarController.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
if (hiddenTabBar) {
[view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)];
} else {
[view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
}
} else {
if (hiddenTabBar) {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)];
} else {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
}
}
}
}];
hiddenTabBar = !hiddenTabBar;
}
when u r clicking on the table view did select row hide the tabbar in the viewcontroller that u r sending
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:YES];
[((AppDelegate*)[[UIApplication sharedApplication]delegate]) hidetabbar];
}
-(void)tabBarControllerView
{
tabBarController = [[UITabBarController alloc] init];
tabBarController.view.backgroundColor = [UIColor blackColor];
tabBarController.delegate = self;
//Add some tabs to the controller...
//----First tab----//
//-----second Tab -----//
//------3rd tab--//
//-----4th tab bar--------//
//-----5th tab bar--------//
[self.view addSubview:tabBarController.view];
[navigationController pushViewController:tabBarController animated:YES];
tabBarController.tabBar.tag=100;
tabBarController.view.hidden = NO;
}
- (void)tabBarController:(UITabBarController *)tabBarControllers didSelectViewController:(UIViewController *)viewController
{
if (tabBarControllers.selectedIndex == 0)
{
}
else if (tabBarControllers.selectedIndex == 1)
{
}
else if (tabBarControllers.selectedIndex == 2)
{
}
else if (tabBarControllers.selectedIndex == 3)
{
}
else if (tabBarControllers.selectedIndex == 4)
{
}
}
hide main tab bar in that view controller where u r doing the did select table and add another tab bar..
try some thing like this it may help u
Add the following Code in didSelect event
UITabBarController *tabBarController = [[UITabBarController alloc]init];
NSArray*tabBarimageArray=[NSArray arrayWithObjects:#"firstTabImage.png",#"secondTabImage.png", nil];
YourFirstTabRootViewController *firstVc = [[YourFirstTabRootViewController alloc]initWithNibName:#"YourFirstTabRootViewController" bundle:nil];
UINavigationController *firstNavigationController=[[UINavigationController alloc]initWithRootViewController:firstVc];
YourSecondTabRootViewController *secondVc = [[YourSecondTabRootViewController alloc]initWithNibName:#"YourFirstTabRootViewController" bundle:nil];
UINavigationController *secondNavigationController=[[UINavigationController alloc]initWithRootViewController:secondVc];
NSArray *VCs = [[NSArray alloc] initWithObjects:firstNavigationController,secondNavigationController nil];
NSArray *names = [NSArray arrayWithObjects:
NSLocalizedString(#"Tab1", #""),
NSLocalizedString(#"Tab2", #""),
nil];
NSMutableArray *tabBarViewControllers = [[NSMutableArray alloc] initWithCapacity:[VCs count]];
NSInteger index = 0;
for (id controller in VCs) {
UINavigationController * navController = controller ;
// THIS SETS UP THE TAB BAR ITEMS/IMAGES AND SET THE TAG FOR TABBAR_ITEM_TAGS
NSString *tabName = [names objectAtIndex:index];
UIImage *tabImage = [UIImage imageNamed:[NSString stringWithFormat:[tabBarimageArray objectAtIndex:index]]];
navController.title = tabName;
UITabBarItem *tempTab = [[UITabBarItem alloc] initWithTitle:tabName
image:tabImage
tag:index];
navController.tabBarItem = tempTab;
[tabBarViewControllers addObject:navController];
index ++;
}
[ tabBarController setViewControllers:tabBarViewControllers];
[self presentModalViewController:tabBarController animated:YES];

UISplitView with SingleViewController

How do I add UISplitView after clicking on the SingleView application? Clearly when the user has successfully logged in then they will see splitView? How is it possible? Please give me guidelines or if possible then code for that because I'm new to iPhone development and I haven't more knowledge for it?
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: 1.90];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.navigationController.view cache:YES];
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:#"MasterViewController" bundle:nil];
if (!masternavigationController) {
masternavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
}
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:#"DetailView" bundle:nil];
if (!splitViewController) {
splitViewController = [[UISplitViewController alloc] init];
splitViewController.viewControllers = [NSArray arrayWithObjects:masternavigationController, detailViewController, nil];
UIViewController *view_controller = (UIViewController *)[navigationController.viewControllers objectAtIndex:([navigationController.viewControllers count]-1)];
[masternavigationController.navigationBar setHidden:TRUE];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
[splitViewController.view setBounds:CGRectMake(0, 0, 1024, 748)];
[splitViewController.view setTransform:CGAffineTransformMakeRotation(M_PI / 2)];
[view_controller.view setTransform:CGAffineTransformMakeRotation(M_PI / 2)];
view_controller.view.tag = 17;
[UIView animateWithDuration:1.05 animations:^{navigationController.view.alpha = 0.0;} completion:^(BOOL finished){
[navigationController.view addSubview:splitViewController.view];
[UIView animateWithDuration:1.00 animations:^{navigationController.view.alpha = 1.0;} completion:nil];}];
rootview *rtview = [[rootview alloc] initWithNibName:#"rootview" bundle:nil];
rtview.delegate = detailViewController;
[detailViewController.view addSubview:rtview.view];
flag = YES;
[rtview release];
}
[UIView commitAnimations];
// [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:#selector(doneAnimation) userInfo:nil repeats:NO];
[masterViewController release];
[detailViewController release];
This is how we have to add splitview controler you have to check the condition weather you are logged in or not and then call this in a method

Switching View through a function

I'm working on an iPhone/iPad application and trying to switch views through a function call, not by a button. I've seen lots of sources switching views triggered by a button, but there's nothing that explains how to switch views triggered by a function. I tried to do this on my own, but it failed. Here's the code that I tried:
- (void)viewDidLoad
{
[super viewDidLoad];
if (self.webview == nil) {
self.webview = [[MainViewController alloc] init];
/* webview initialized with storyboard */
if (self.view.superview == nil) {
[self.view insertSubview:self.webview.view atIndex:0];
}
[storyboard release];
}
}
This is viewDidLoad of the viewController.m. First, it shows WebView.
- (void)changeView {
self.normview = [[AlternateViewController alloc] init];
/* normview initialized with storyboard */
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
[self.webview viewWillDisappear:YES];
[self.webview viewDidDisappear:YES];
[self.webview.view removeFromSuperview];
[self.view insertSubview:self.normview.view atIndex:0];
[self.normview viewWillAppear:YES];
[self.normview viewDidAppear:YES];
[UIView commitAnimations];
}
And when this changeView function (in a viewController.m) is called, It should change the view from webview to normview (actually, it works fine when the same code is triggered by a button). But when I call this function in other file (not viewController.m), such as
ViewController *viewcontroller = [[ViewController alloc] init];
[viewcontroller changeView];
It doesn't work. Anyone can give a clue to solve this or an alternative way? (ps. I'm testing on iPad.)
You can switch views with this function:
YourView *screen = [[YourView alloc] initWithNibName:nil bundle:nil];
screen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:screen animated:YES];
[screen release];
You can set the modaltransitionstyle to your willings.
Don't forget to import your headerfile at the top of your class.
#import "YourView.h"

How to hide the tab bar on click of a tab in an iPhone app

I am doing a multi view app, in that I have 4 tabs, and I have view controllers in each tab. In one tab I have grouped table view controller, on click of that tab it will go to that grouped table view. Every thing is going fine.
But last row of the table is hidden under tab bar, so I need to hide the tab bar when I enter into that screen. How can I do this?
I am using this in Appdelegate to create tabs programmatically.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UINavigationController *localNavigationController;
tabBarController = [[UITabBarController alloc] init];
NSMutableArray *localControllersArray = [[NSMutableArray alloc] initWithCapacity:5];
//add first tab View Controller
RootViewController *ViewController;
ViewController = [[RootViewController alloc] initWithTabBar];
localNavigationController = [[UINavigationController alloc] initWithRootViewController:ViewController];
[localControllersArray addObject:localNavigationController];
[localNavigationController release];
[ViewController release];
//add second tab View Controller
StudentDataEntry *GroupViewController;
GroupViewController = [[StudentDataEntry alloc] initWithTabBar];
localNavigationController = [[UINavigationController alloc]
initWithRootViewController:GroupViewController];
[localControllersArray addObject:localNavigationController];
[localNavigationController release];
[GroupViewController release];
}
if your last row is not visible in your view then there is no need to hide tab bar for that you have to make your table view height according to that, a tab bar is 48 px so minus this 48 px height from your table view height and also if there is a navigation bar at the top then also minus 44 more px from height then it will be visible. And also you can set content inset for table view to make it visible.
Try this
yourviewcontroller.hidesBottomBarWhenPushed=YES;
Try this:
BOOL hiddenTabBar = NO;
- (void) hidetabbar {
NSArray *array = self.tabBarController.view.subviews;
NSLog(#"array SubView %#",array);
[UIView animateWithDuration:1.0 delay:0.0f options:UIViewAnimationCurveLinear animations:^(){
for(UIView *view in self.tabBarController.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
if (hiddenTabBar) {
[view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)];
} else {
[view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
}
} else {
if (hiddenTabBar) {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)];
} else {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
}
}
}
} completion:^(BOOL isfinsihed){
hiddenTabBar = !hiddenTabBar;
}];
}

UITabBar wont hide

I have a UINavigationController in a UITabBarController, and I can't seem to get a pushed viewController's tabBar to hide.
I am using the following code to hide it:
Before it gets pushed:
tpsv.hidesBottomBarWhenPushed = YES;
tpsv.tabBarController.hidesBottomBarWhenPushed = YES;
viewWillAppear:
self.tabBarController.tabBar.hidden = YES;
AppDelegate *del = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[[[del tabController] tabBar]setHidden:YES];
But none of the above work.
If you could tell me how to fix this, that would be great.
You set this before you push the new view controller:
MyViewController *myVC = [[[MyViewController alloc] init] autorelease];
myVC.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:myVC animated:YES];
[EDIT: comment re usage]
Just noticed you say you tried this. Not sure what else you're doing in the context of pushing your VC or configuring it but this does work fine. It's how I do this exact thing in my apps.
- (void) hideTabBar:(UITabBarController *) tabbarcontroller {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
}
}
[UIView commitAnimations];
}
- (void) showTabBar:(UITabBarController *) tabbarcontroller {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
for(UIView *view in tabbarcontroller.view.subviews)
{
NSLog(#"%#", view);
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)];
}
}
[UIView commitAnimations];
}
I've faced the same problem with
myVC.hidesBottomBarWhenPushed = YES;
It does'nt remove the tab bar in subsequent views. May be it's deprecated. You should'nt face this problem with the setHidesBottomBarWhenPushed: command. Try using the following for views:
MyViewController *myVC = [[[MyViewController alloc] init] autorelease];
[myVC setHidesBottomBarWhenPushed:YES];
[self.navigationController pushViewController:myVC animated:YES];