UINavigationController animation - iphone

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.

Related

How to add a tab bar to flipside view only

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.

UITabBarController disappears when pushViewController

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

call navigationcontroller with modalview?

I have a problem, I have made this:
Impostazioni *impostazioni=[[Impostazioni alloc] initWithNibName:#"Impostazioni" bundle:nil];
[self.navigationController presentModalViewController:aiuto animated:YES];
But I want to preserve the navigation bar in this modality:
[self.navigationController pushViewController:aiuto animated:YES];
[self.navigationController.navigationBar.backItem setTitle:#"iCalory"];
And I want use presentModalView how can I this? thanks
To add navigation controller in your code,
Impostazioni *impostazioni=[[Impostazioni alloc] initWithNibName:#"Impostazioni" bundle:nil];
UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController: impostazioni] autorelease];
[self.navigationController presentModalViewController:navigationController animated:YES];
Just add your view controller to a new navigation controller and present the navigation controller modally:
UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController: aiuto] autorelease];
[self presentModalViewController navigationController];

How to add navigation controller to windowbased app

I have a window based app. I added two viewcontrollers and one Tabbarcontroller to that. Now I want to navigate each viewcontroller to next view. I tried but can't find the solution. Can anyone please help me?
When you add the tab bar on window, add like this-
NSMutableArray * viewControllers = [[NSMutableArray alloc]init];
FirstViewController * firstViewController = [[FirstViewController alloc]initWithNibName:#"FirstViewController" bundle:nil];
UINavigationController * nvc = [[UINavigationController alloc] initWithRootViewController:firstViewController];
[firstViewController release];
[viewControllers addObject:nvc];
[nvc release];
SecondViewController * secondViewController = [[SecondViewController alloc]initWithNibName:#"SecondViewController" bundle:nil];
nvc = [[UINavigationController alloc] initWithRootViewController:secondViewController];
[secondViewController release];
[viewControllers addObject:nvc];
[nvc release];
UITabBarController * tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = viewControllers;
[window addSubview:tabBarController.view];
EDIT -
Whenever you want to navigate in any one of the controller. All you need is to call
[self.navigationController pushViewController:anotherViewController animated:YES];
And you will get exactly what you want. :)
UINavigationController *urNavController = [[UINavigationController alloc] initWithRootViewController:rootController];
If you want to show this on the window
[window addSubview:urNavController.view];
use like this
secondViewController *obj=[[[secondViewController alloc] initWithNibName:#"secondViewController" bundle:nil] autorelease];
UINavigationController *navBar=[[UINavigationController alloc] initWithRootViewController:obj];
[self.navigationController pushViewController:navBar animated:YES];
[navBar release];

How to push a new viewController in a tableview which is a inserted view of a navigationcontroller?

I have a HomeViewController.m in which I push SpecificViewController by self.navigationController,
SpecificViewController *specificViewController= [[SpecificViewController alloc] initWithNibName:#"SpecificViewController" bundle:nil];
[self.navigationController pushViewController:specificViewController animated:YES];
And in SpecificViewController.m I insert a subview
FirstViewController *firstViewController = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
[self.view insertSubview:firstViewController.view atIndex:0];
And in FirstViewController.m, there is a tableview. The question is how can I push a new ViewController by navigationController, I have try below, but it does not work.
-(void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailTableViewController *detail =
[[DetailTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
[self.navigationController pushViewController:detail animated:YES];
[detail release];
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}
I still tried a new UINavigationController,
UINavigationController *NEWnavigationController;
NEWnavigationController=[[UINavigationController alloc] init];
[NEWnavigationController pushViewController:detail animated:YES];
but it still did not work. Could you give me any suggestion?
There are quite a few things wrong with your approach.
First, is SpecificViewController the first view controller you load? If yes, then you do not push this view controller rather you set it as the root view controller in your application delegate as shown below
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:[[SpecificViewController alloc] init];
This will ensure that your Navigation controller is setup and the first view controller that appears is the SpecificViewController
Secondly, you dont insert a view controller as a subview. If you are trying to load a second view controller then you push that onto your navigation controller stack. You can do that from SpecificViewController as shown below
FirstViewController *firstViewController =[[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
[self.navigationController pushViewController:firstViewController animated:YES];