Not in AppDelegate create TabBarController - iphone

This is RegisterViewController.m part
if ([message isEqualToString:#"registerOK"]){
self.findViewController = [[FindViewController alloc] initWithNibName:nil bundle:NULL];
self.friendViewController = [[FriendViewController alloc] initWithNibName:nil bundle:NULL];
self.goViewController = [[GoViewController alloc] initWithNibName:nil bundle:NULL];
self.settingViewController = [[SettingViewController alloc] initWithNibName:nil bundle:NULL];
self.findNavigationController = [[UINavigationController alloc] initWithRootViewController:self.findViewController];
self.friendNavigationController = [[UINavigationController alloc] initWithRootViewController:self.friendViewController];
self.goNavigationController = [[UINavigationController alloc] initWithRootViewController:self.goViewController];
self.settingNavigationController = [[UINavigationController alloc] initWithRootViewController:self.settingViewController];
//[self.findNavigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"nav-bar-background-light.png"] forBarMetrics:UIBarMetricsDefault];
[self.findNavigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"nav-bar-background-light.png"] forBarMetrics:UIBarMetricsDefault];
[self.friendNavigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"nav-bar-background-light.png"] forBarMetrics:UIBarMetricsDefault];
[self.goNavigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"nav-bar-background-light.png"] forBarMetrics:UIBarMetricsDefault];
[self.settingNavigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"nav-bar-background-light.png"] forBarMetrics:UIBarMetricsDefault];
NSArray *allViewController = [[NSArray alloc] initWithObjects:self.findNavigationController,self.friendNavigationController,self.goNavigationController,self.settingNavigationController, nil];
self.tabBarController = [[UITabBarController alloc] init];
[self.tabBarController setViewControllers:allViewController];
UIWindow *window = [UIApplication sharedApplication].keyWindow;
[self.view addSubview:self.tabBarController.view];
[window setRootViewController:self];
}
I want to create a TabBarController in RegisterViewController. How can I do it?
In AppDelegate.m I have an if which does: if already login then create TabBarController, if not go to RegisterViewController, then if register complete I want to create TabBarController. How to do this? Thanks.

You could just show your login and register views on top of tabBarController.view by [self.tabBarController presentViewController:] or such.

Make public method in AppDelegate and create there tabbar as usual.
And call this method where you need:
[(ASAppDelegate *)[[UIApplication sharedApplication] delegate]yourMethod]

Related

Creating TabBar programmatically only for one ViewController not in AppDelegate

I want to create a tabBar in my app but only in a detailView not in the AppDelegate. I am searching how to do this in google but everything what I have figured out is in AppDelegate.m
I am trying to do something like this. This shows me a Tab bar with two buttons(without names) but I want to go from one FirstViewController with tabBar, to one of the two items SecondViewController or ThirdViewController with a navigationBar with one backItemButton for get back to the FirstViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self setupTabBar];
}
- (void) setupTabBar {
tabBars = [[UITabBarController alloc] init];
NSMutableArray *localViewControllersArray = [[NSMutableArray alloc] initWithCapacity:4];
YPProfileViewController *profile = [[YPProfileViewController alloc] init];
YPProfileViewController *profile2 = [[YPProfileViewController alloc] init];
[localViewControllersArray addObject:profile];
[localViewControllersArray addObject:profile2];
tabBars.tabBarItem = profile2;
tabBars.viewControllers = localViewControllersArray;
tabBars.view.autoresizingMask==(UIViewAutoresizingFlexibleHeight);
[self.view addSubview:tabBars.view];
}
at least this works for me.
UIViewController *vc1 = [[UIViewController alloc] init];
vc1.title = #"FIRST";
vc1.view.backgroundColor = [UIColor blueColor];
UIViewController *vc2 = [[UIViewController alloc] init];
vc2.title = #"SECOND";
vc2.view.backgroundColor = [UIColor redColor];
UITabBarController *tabBar = [[UITabBarController alloc] init];
tabBar.viewControllers = #[vc1,vc2];
tabBar.selectedIndex = 1;
tabBar.view.frame = CGRectMake(50, 50, 220, 320);
[tabBar willMoveToParentViewController:self];
[self.view addSubview:tabBar.view];
[self addChildViewController:tabBar];
[tabBar didMoveToParentViewController:self];

need to set tabbar image in iphone?

i have selected tab bar based application from templates. in that i need to set the custom image i have tried like given below
UIViewController *viewController1 = [[[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil] autorelease];
UINavigationController *view1=[[UINavigationController alloc]initWithRootViewController:viewController1];
UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil] autorelease];
UINavigationController *view2=[[UINavigationController alloc]initWithRootViewController:viewController2];
UIViewController *viewController3 = [[[SecondViewController alloc] initWithNibName:#"ThirdViewController" bundle:nil] autorelease];
UINavigationController *view3=[[UINavigationController alloc]initWithRootViewController:viewController3];
UIViewController *viewController4 = [[[SecondViewController alloc] initWithNibName:#"MainViewController" bundle:nil] autorelease];
UINavigationController *view4=[[UINavigationController alloc]initWithRootViewController:viewController4];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.delegate=self;
self.tabBarController.viewControllers = [NSArray arrayWithObjects:view1,view2,view3,view4, nil];
[self.tabBarController.tabBarItem setImage:[UIImage imageNamed:#"h.png"]];
one more way i have tried
[[_tabBarController tabBar] setBackgroundImage:[UIImage imageNamed:#"h.png"]];
in the second way there is image applied but it's a background.
so i need individually like home button something like that....
how to set this...
thanks....
You an set the images in UIViewControllers's TabBarItems like..
viewcontroller1.tabBarItems.image = [UIImage imageNamed:#"your image1"];
viewController2.tabBarItems.image = [UIImage imageNamed:#"your image2"];
viewController3.tabBarItems.image = [UIImage imageNamed:#"your image3"];
viewController3.tabBarItems.image = [UIImage imageNamed:#"your image3"];
You can do like,
NSArray *tabs = tabBarController.viewControllers;
UIViewController *tab1 = [tabs objectAtIndex:0];
tab1.tabBarItem.image = [UIImage imageNamed:#"clockicon.png"];
UIViewController *tab2 = [tabs objectAtIndex:1];
tab2.tabBarItem.image = [UIImage imageNamed:#"nearest.png"];

NavigationController done button is not showing

When i press the infobutton on the mainviewcontroller it shows navbar and uitextview modally but doesn't shows done button.
- (void) modalViewAction:(id)sender
self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]autorelease];
[self.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
_viewController = [[ModalViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:_viewController];
navigationController.navigationBar.tintColor = [UIColor brownColor];
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(Done:)] autorelease];
[self.navigationController presentModalViewController:self.viewController animated:YES];
[navigationController release];
Anyone have ideas why is that Done Button is missing from the navigationcontroller.
Thanks for help.
Your presenting it Modally:
[self.navigationController presentModalViewController:self.viewController animated:YES];
You need to push it onto the navigation stack:
[self.navigationController pushViewControler:self.viewController animated:YES];
Now the NavigationController will take care of the back button for you.
You have to either:
push the view controller onto the navigation controller (as Hubert
explained), or
create a new UINavigationController and set the
viewController as the rootViewController of that
UINavigationController and then you can do:
[self.navigationController
presentModalViewController:newNavigationController animated:YES];
I added following statement
[_viewController.navigationItem setLeftBarButtonItem:button animated:YES];
to the below code and now Done button is showing on the navigation controller
- (void) modalViewAction:(id)sender
{
self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]autorelease];
[self.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
_viewController = [[ModalViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:_viewController];
UIBarButtonItem * button = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemDone target:self action:#selector(dismissView:)] autorelease];
[_viewController.navigationItem setLeftBarButtonItem:button animated:YES];
navigationController.navigationBar.tintColor = [UIColor brownColor];
[self.navigationController presentModalViewController:self.viewController animated:YES];
[self.view addSubview:navigationController.view];
[navigationController release];
}
So my issue is solved.
Thanks for help

modalviewcontroller shows gap after loading

Modalviewcontroller is showing gap after loading. Gap is after staus bar which moved modalviewcontroller down and gap shows me main window. So how i can remove this gap which is showing between status bar and modalviewcontroller. There is no interface builder involved. Creating everything programmtically. Help for this will be really appreciated.
UIButton *button = [UIButton buttonWithType:UIButtonTypeInfoLight];
[button addTarget:self action:#selector(displayModalViewaction:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *infoItem = [[UIBarButtonItem alloc] initWithCustomView:button];
- (void)displayModalViewaction: (id) sender
{
self.viewController = [[Infoviewcontroller alloc] init];
UINavigationController *navigationController=[[UINavigationController alloc] init];
navigationController.navigationBar.tintColor = [UIColor brownColor];
[navigationController pushViewController:_viewController animated:YES];
[self.view addSubview:navigationController.view];
}
Thanks
In your _viewController, you need to update this code if you want to hide the gap -
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
But ideally it needs to be fixed by-
[self presentModalViewController:navigationController animated:YES];
Not sure why it is not working for you.
Assuming this code is in a UIViewController you probably want to do something like this.
self.viewController = [[[Infoviewcontroller alloc] init] autorelease];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
navigationController.navigationBar.tintColor = [UIColor brownColor];
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
By adding the view frame size [self.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; fixed the gap between status bar and modal view.

Uitabbarcontroller in a UIViewController not in the appdelegate

How do I integrate a UITabbarcontroller in a UIViewController class not in the app delegate? I was suppose to make a login view and after it the UITabBarController appears which was created in a UIViewController class? Can anyone suggest what needs to be done? thanks
You can still put the UITabBarController in the App Delegate, when the login is done, just tell the app delegate, and switch the them:
self.window.rootViewController=tabBarController;
if your Application is Navigation Based App, then Create TabBarController(with ViewControllers how many you want to add) and add it on Navigation Controller, like this
UITabBarController *tabBarController = [Utility configureMessagesTabBArController];
self.navigationController.navigationBarHidden=YES;
[self.navigationController pushViewController:tabBarController animated:YES];
[tabBarController release];
here is configureMessagesTabBArController Method from Utility class
+(UITabBarController *)configureMessagesTabBArController
{
UITabBarController *tabBarController = [[UITabBarController alloc]init];
AktuellesViewController *aktuelles_Controller = [[AktuellesViewController alloc]init];
TermineViewController *termine_Controller = [[TermineViewController alloc]init];
TopTenViewController *topTen_Controller = [[TopTenViewController alloc]init];
MediathekViewController *mediathek_Controller = [[MediathekViewController alloc]init];
KontaktViewController *kontakt_Controller = [[KontaktViewController alloc] init];
UINavigationController *nav1 = [[UINavigationController alloc]initWithRootViewController:aktuelles_Controller];
UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:termine_Controller];
UINavigationController *nav3 = [[UINavigationController alloc]initWithRootViewController:topTen_Controller];
UINavigationController *nav4 = [[UINavigationController alloc]initWithRootViewController:mediathek_Controller];
UINavigationController *nav5 = [[UINavigationController alloc]initWithRootViewController:kontakt_Controller];
nav1.navigationBar.tintColor = [UIColor blackColor];
nav2.navigationBar.tintColor = [UIColor blackColor];
nav3.navigationBar.tintColor = [UIColor blackColor];
nav4.navigationBar.tintColor = [UIColor blackColor];
nav5.navigationBar.tintColor = [UIColor blackColor];
[tabBarController setViewControllers:[[NSArray alloc]initWithObjects:nav1,nav2,nav3,nav4,nav5,nil]];
[nav1 release];
[nav2 release];
[nav3 release];
[nav4 release];
[nav5 release];
[aktuelles_Controller release];
[termine_Controller release];
[topTen_Controller release];
[mediathek_Controller release];
[kontakt_Controller release];
return tabBarController;
}