I already have the basic code for a utility application, but when the application flips to the second view I want to add a tabbarItem to the bottom of the flipped view only, if the view is flipped back to the original view the tab bar shouldn't show up. How can I add this feature, I'm using simulator 4.1 by the way, thanks!
Here's the code that shows the flipped side when the button is clicked, I want it to flip to a tab bar controller instead.
- (IBAction)showInfo:(id)sender {
FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:#"FlipsideView" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}
You can hide the UITabbar by using the following code
[yourTabBar setHidden :YES];
and show it using the following code
[yourTabBar setHidden:NO];
By Show/Setup do you mean adding the tabbar controller on the view??Well i am assuming that..You can Add the tabbar controller as a rootviewcontroller of your window i.e. your AppDelegate.Here is the sample Code:
UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
UINavigationController *navCon1=[[UINavigationController alloc] initWithRootViewController:viewController1];
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
UINavigationController *navCon2=[[UINavigationController alloc] initWithRootViewController:viewController2];
UIViewController *viewController3=[[ThirdViewController alloc] initWithNibName:#"ThirdViewController" bundle:nil];
UINavigationController *navCon3=[[UINavigationController alloc] initWithRootViewController:viewController3];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navCon1, navCon2,navCon3, nil];
self.window.rootViewController = self.tabBarController;
You're switching between two UIViewControllers, right? Let the second view controller, the one that appears after flipping, be a UITabBarViewController.
Related
Titles are not showing after the home screen. I have put UITabBarController after the first screen. First screen hasn't got a UITabBarController. I am not sure the way I have implemented the tab.
I have set titles in every view controller by self.title = #"title". Titles are showing in tab items properly.
AppDelegate.m:
UIViewController *loginView= [[[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil] autorelease];
UINavigationController *loginViewNavController = [[UINavigationController alloc] initWithRootViewController:loginView ];
self.navigationController = loginViewNavController;
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
LoginViewController.m:
-(IBAction)navigateMainMenu:(id)sender{
tabBarController = [[UITabBarController alloc] init];
MyAccountsViewController *vc1 = [[MyAccountsViewController alloc] initWithNibName:#"MyAccountsViewController" bundle:nil];
DepositsViewController *vc2 = [[DepositsViewController alloc] initWithNibName:#"DepositsViewController" bundle:nil];
MoreViewController *vc3 = [[MoreViewController alloc] initWithNibName:#"MoreViewController" bundle:nil];
PayTransViewController *vc4 = [[PayTransViewController alloc]init];
NSArray* controllers = [NSArray arrayWithObjects:vc1,vc4, vc2, vc3, nil];
tabBarController.viewControllers = controllers;
[self.navigationController pushViewController:tabBarController animated:YES];
[mainMenuViewController release];
If you set self.title = #"Title". This title will set in navController title. But In your TabBarController, every items are ViewController. Not an navigationController.
Issue: What you release in this line
[mainMenuViewController release];
mostly display title with bellow trickes :-
1. Self.title=#"Your Titile";
2. self.navigationItem.title=#"your Title";
3. when you using UItabBarController you can set Particular Viewcontroller as par your code Title like:-
vc1.title=#"your Title";
vc2.title=#"your Title";
vc3.title=#"your Title";
vc4.title=#"your Title";
I suggest you not you use tabbarcontroller inside a navigationcontroller. If you are using tabbarcontroller it should be the rootViewcontroller.
I want to create something like below.
RootView does not have TabBar, From the second view there should be TabBar.
What I have currently done is, I am using UINavigationController as controller calass
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIViewController *rootController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
navigationController = [[UINavigationController alloc] initWithRootViewController:rootController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
But how can I use UITabBar with tabBarController from SecondViewController?
create the objects of the second view and then push your view with the tabbarcontroller
From Storyboard embed your SecondViewController in TabBar. Select your controller and go to Editor -> Embed in -> TabBar Controller! I'm from my mobile..sorry if i have any mispells!
You need to push your Tabbar controller's object. Initialize your tab bar controller's object and add all other controller objects to the tabbar controller's viewcontroller array.
On button action:-
1> Initialize tab bar controller and suppose you name its object as objTab;
2> objTab.viewcontrollers = [NSArray arrayWithObjects:..] ---> Objects of all viewcontrollers that are a part of your tab bar controller. Thus all objects need to be created first.
3> self.navigationcontroller pushViewController: objTAb
Something like this should do the trick (not using ARC):
//vc1, vc2, vc3 = your view controllers
NSArray *viewControllersArray = [NSArray arrayWithObjects:vc1,vc2,vc3, nil];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
[tabBarController setViewControllers:viewControllersArray];
[self.navigationController pushViewController:tabBarController animated:YES];
[tabBarController release];
What you want to do is create the UITabBarController and push that along the navigation stack.
For Sample Write loadnewview method at appdelegate .Use buttonPressed method for button action or any object action of first view controller as shown below to display tab bar from second view controller.
I have taken two tabs for sample so I wrote Capacity as 2. You can take up to 5.
-(IBAction)buttonPressed:(id)sender
{
HomeViewController *homeVC=[[HomeViewController alloc]initWithNibName:#"HomeViewController" bundle:nil];
[self.navigationController pushViewController:homeVC animated:YES];
[appDelegate loadnewview];
}
-(void)loadnewview
{
if(!self.tabBarController)
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.delegate=self;
NSMutableArray *localcontrollerarray = [[NSMutableArray alloc] initWithCapacity:2];
UIViewController *viewController1 = [[HomeViewController alloc] initWithNibName:#"HomeViewController" bundle:nil];
UINavigationController *navi1 = [[UINavigationController alloc] initWithRootViewController:viewController1];
[localcontrollerarray addObject:navi1];
UIViewController *viewController2 = [[ScanViewController alloc] initWithNibName:#"ScanViewController" bundle:nil];
UINavigationController *navi2 = [[UINavigationController alloc] initWithRootViewController:viewController2];
[localcontrollerarray addObject:navi2];
self.tabBarController.viewControllers = localcontrollerarray;
[self.window addSubview:self.tabBarController.view];
}
use this type of method in AppDelegate.m and property-synthesize UITabBarController and store array of viewcontroller in it also in application didFinishLaunchingWithOptions method just assign navigationViewController as a RootViewController like bellow..
RootViewController *masterViewController = [[[RootViewController alloc] initWithNibName:#"RootViewController" bundle:nil] autorelease];
self.navigationController = [[[UINavigationController alloc] initWithRootViewController:masterViewController] autorelease];
after then when you want to add TabBar to any view at that time call this bellow method like this..
[appDelegate addTabBarControllerInwindow];
-(void)addTabBarControllerInwindow
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.window cache:YES];
[self.navigationController.view removeFromSuperview];
[self.window addSubview:[tabBarController view]];//tabBarController.view
[UIView commitAnimations];
}
Create an Application using Tab Bar Controller and on the ViewDidLoad method of the view controller for which you want to hide the tab bar use code:
[self.tabBarController.tabBar setHidden:YES];
And don't forget to unhide the tab bar using the same code replacing NO instead of YES for the view controller for which you want to show the tab bar.
I have a tabBar app with two tabs. Each tab has its own navigationController implemented this way:
FirstViewController *firstController = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
UINavigationController *firstNavController = [[UINavigationController alloc] initWithRootViewController:firstController];
SecondViewController *secondController = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
UINavigationController *secondNavController = [[UINavigationController alloc] initWithRootViewController:secondController];
tabBar.viewControllers = [NSArray arrayWithObjects:firstNavController, secondNavController, nil];
When I want to push a view into one tab I use this:
[self.navigationController pushViewController:activityController animated:YES];
And when I am on a pushed view and I want to pop the view I use:
[self.navigationController popViewControllerAnimated:YES];
The push animation works great but in the pop animation only the top bar (the NavigationController) gets animated and the view disappears without the animation. What can be wrong?
Try using [self.navigationController popToRootViewControllerAnimated:YES];
Instead of [self.navigationController popViewControllerAnimated:YES];
and tell me if this works. Remember for netsted navigation controllers.
I have an app with a UITabBar and a NavigationController. When I use pushViewController the new ViewController appears with the NavigationController and the back button, but the UITabBarController disappears. I know there are lots of questions here about the same, but any of them have solved my question, maybe because I dont understand the answers given.
Any suggestion?
ActivityViewController *activityController = [[ActivityViewController alloc] initWithNibName:#"ActivityViewController" bundle:nil];
[self.navigationController pushViewController:activityController animated:NO];
That's probably because Your rootViewController (for your main UIWindow) is set to a Navigationcontroller instead of your TabBar.
If you don't want the Tabbar to go away just set it as your root view controller
Do the following in appDidFinishLaunching in your AppDelegate
LoginViewController *loginViewController = [[FirstViewController alloc] init];
UINavigationController *loginNavigationController = [[UINavigationController alloc] loginViewController];
[firstViewController release];
self.window.rootViewController = loginNavigationController;
Then in your Login Page:
- (void)loginSuccessfull
{
FirstViewController *firstViewController = [[FirstViewController alloc] init];
UINavigationController *firstNavigationController = [[UINavigationController alloc] initWithViewController:firstViewController];
[firstViewController release];
SecondViewController *secondViewController = [[SecondViewController alloc] init];
UINavigationController *secondNavigationController = [[UINavigationController alloc] initWithViewController:secondViewController];
[secondViewController release];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
[tabBarController setViewControllers:
[NSArray arrayWithObjects:firstNavigationController, secondNavigationController, nil]];
[firstNavigationController release];
[secondNavigationController release];
[self.navigationController pushViewController:tabBarController];
[tabBarController release];
}
If you still need the navigation functionality just wrap your viewControllers inside a UINavigationController, and add the serounding navigationController to the tabBar, instead of the UIViewcontroller
i need to implement a multiview app really complex to me and i need some advice. The multiview app is something like:
First view: Normal UIViewController with one button, when i push it go to second view
Second view(aka mainview): a Windows with Tab Bar with 2 tabbar item who switch between:
Second view A: Normal UIViewController with some elements
Second view B: UITableViewController
Can someone give me an advice where to start reading or some examples?
thx
my advice is to read sample code form apple there you can also find coding how to s so good luck, or you can find example codes all over the stack just search. for example navigation based app:
UINavigationController doesn't work in a the moreNavigationController of a UITabBarController
or simple transition:
SecondViewController *screen = [[SecondViewController alloc] initWithNibName:nil bundle:nil];
screen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:screen animated:YES];
[screen release];
hope it helps bye
wblade
You need to start with view based application. And then create a UITabbarController in you appDelegate file.
Appdelegate.h
UITabBarController *tabBarController;
// set properties
Appdelegate.m
// Synthsize
tabBarController = [[UITabBarController alloc] init];
tabBarController.delegate=self;
//Adding Search,Nearby,Map,AboutUs,Favorites Tabs to tabBarController
Search * search = [[Search alloc] init];
UINavigationController *searchNav = [[UINavigationController alloc] initWithRootViewController:search];
Nearby* nearby = [[Nearby alloc] init];
UINavigationController *nearbyNav = [[UINavigationController alloc] initWithRootViewController:nearby];
Map* map = [[Map alloc] init];
UINavigationController *mapNav = [[UINavigationController alloc] initWithRootViewController:map];
AboutUs* aboutUs = [[AboutUs alloc] init];
UINavigationController *aboutUsNav = [[UINavigationController alloc] initWithRootViewController:aboutUs];
Favorites* favorites = [[Favorites alloc] init];
UINavigationController *favoritesNav = [[UINavigationController alloc] initWithRootViewController:favorites];
NSArray* controllers = [NSArray arrayWithObjects:searchNav,nearbyNav,mapNav,aboutUsNav,favoritesNav, nil];
tabBarController.viewControllers = controllers;
[window addSubview:tabBarController.view];
You can accordingly manage in which tab you want to place navigation controller or only a view controller.
Then in each of the view controllers mentioned above you need to implement
- (id)init {}
in which you can set Tab name and image.