Animate New View from Tab Bar Application Template XCode - iphone

I have created a new Tab Bar Application template in xcode. How should I properly setup a new view that animates in (Slide Up) when a button is pressed? I've seen this done using the NavigationController.
I've added a navigation bar and a button with an action that adds a sub view using this code:
(IBAction)newPost:(id)sender
{
// Load UIViewController from nib
PostViewController *screen = [[PostViewController alloc] initWithNibName:#"PostViewController" bundle:nil];
// Add to UINavigationController's stack, i.e. the view for this UITabBarController view
[self.view addSubview:screen.view];
// Release music, no longer needed since it is retained by the navController
[screen release];
}

I'm not sure if this is what you're asking, but if you just want a new view controller to present itself modally upward just do this.
1.) New File --> View Controller
2.)
newViewcontroller *viewController = [[newViewcontroller alloc] initWithNibName:#"newViewcontroller" bundle:nil];
[self presentModalViewController:viewController animated:YES];
[viewController release];

Related

don't understand how to use navigation controller in iphone

I'm extremly new to iphone and I have the following misunderstanding.
All over internet the tutorials about how to use NavigationController programatically it says:
NavigationController must be declared in applicationDidFinishLaunching and must be init with a root.After that you can add views to it.
I have this:
A UIViewController class meaning(AdiViewController.h, AdiViewController.m and AdiViewController.xib) and no Delegate file meaning no applicationDidFinishLaunching method.
What I wanna do is from my class-AdiViewController when pressing a button to go to another view.
I understand that I need a NavigationController which should retain my views having the root AdiViewController.
But my problem is where should I initializate that NavigationController in viewDidAppear??...cause I don't have the Delegate files.
If you could provide a minimal example with this small issue of mine it would be great.I'm sure that for those how are senior this is nothing but still I don't get it.Thanks
NavigationController must be declared in applicationDidFinishLaunching -> this is not true.
In your AdiViewController if you have button when you push that button you want to load navigation Controller right ?
// Hook this IBAction to your button in AdiViewController
- (IBAction)pushNavController
{
AnotherViewController* rootView = [[AnotherViewController alloc] initWithNibName:#"Anotherview" bundle:nil];
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:rootView];
[rootView release];
[self presentModalViewController:navController animated:YES];
[navController release];
}
If you are in AnotherViewController i.e., you are in root view controller of Navigation controller. You need to push and pop view controllers from there. For example if you have a button in AnotherViewController:
// push next view controller onto navigation controller's stack
- (IBAction)pushNextViewController
{
NextViewController* nextView = [[NextViewController alloc] initWithNibName:#"NextView" bundle:nil];
[self.navigationController pushViewController:nextView animated:YES];
[nextView release];
}
// Similarly if you want to go back to AnotherViewController from NextViewController you just pop that from navigation controller's stack
- (IBAction)pushNextViewController
{
[self.navigationController popViewControllerAnimated:YES];
}

UINavigationController displaying title, but not view

In my app, I've got a mainViewController that I'm trying to use for holding and controlling a couple of main view for my app. I first loaded up a splash screen, but then am wanting to have it so that when a user taps on the splash screen, they are taken to the main menu.
I've got the splash screen part working fine, but I'm having trouble with the NavigationController part.
[splashView.view removeFromSuperview];
mainMenu = [[menuScreenViewController alloc] initWithNibName:#"menuScreenViewController" bundle:nil];
mainMenu.title = #"Menu";
mainNavController = [[UINavigationController alloc] init];
[mainNavController pushViewController:mainMenu animated:NO];
[MAINVC.view addSubview:mainNavController.view];
[mainMenu release];
[mainNavController release];
[splashView release];
(MAINVC is defined elsewhere to be my main view controller).
Anyway, when I do this, I get the navigation controller with the title 'Menu', but the view contained in the mainMenu view controller do not show up in the navigation controller.
If I simply add the mainMenu's view ass a subview of MAINVC.view, it shows up correctly.
Any suggestions on how to get it to show up in my navigation controller?
avery, you're going to need to initialize the navigation controller with the mainMenu as its root view controller, instead of just initializing and then pushing a new view on. It needs that root view controller to work.
mainMenu = [[menuScreenViewController alloc] initWithNibName:#"menuScreenViewController" bundle:nil];
mainMenu.title = #"Menu";
mainNavController = [[UINavigationController alloc] initWithRootViewController:mainMenu];
//ADD MODAL SPLASH SCREEN HERE
[MAINVC.view addSubview:mainNavController.view];
[mainMenu release];
[mainNavController release];
[splashView release];
As the comment above shows, I'll suggest that you initialize this way, and then then add your splash screen to the nav controller as a modalViewController. This will prevent any delay you might have from the mainMenu initialization, when you tap the touchscreen. Then, when the modal view receives a touch, you can call:
[self.parentViewController dismissModalViewControllerAnimated:YES];

Utility App with Navigation Controller and Table View on FlipSide

I am relatively new to the whole MVC way of looking at things.
I have an application that is based on the "Utility" Application template. Everything in the MainView and FlipsideView is working great but now I need to add a TableView and Navigation Controller to the flipside. Without the navigation bar being on the MainView.
So only once the user has tapped the info light button will the nav bar display on the flipside with a table view.
I have been able to impliment the Table View on the side and populate it with data from an array.
I am now struggling to link in a navigation controller so that the tableview can become interactive.
When I place the nav bar code into the app delegate it appears on the MainView and not the flipside view.
Where do I place the navigation bar code so that it will display on the flipsideview. I cannt seem to get the code in the right place.
Also I am not sure I have the right code, do I put the UINavigationController code in the FlipSideViewController.m ?
I am not grasping the concept of the naivgation controller fully I think . . .
Here is the code to bring up the FlipView
- (IBAction)showInfo
{
TableViewController *controller = [[TableViewController alloc] initWithNibName:#"TableViewController" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}
Now I need to get the TableViewController to have a navigation controller and a table view
Thanks in advance.
After you create your table view controller, create a navigation controller that contains this table view controller as the root. Then, present this navigation controller modally, instead of your table view controller.
I prefer to do this programmatically, so here's the code I use:
- (IBAction)showInfo
{
TableViewController *controller = [[TableViewController alloc] initWithNibName:#"TableViewController" bundle:nil];
controller.delegate = self;
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
[controller release];
navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:navController animated:YES];
[navController release];
}
In your table view controller, set up its navigation item to contain a button that, when tapped, causes your main view controller to dismiss the modal navigation controller (thus flipping back to itself).

Presented modal navigationcontroller under current navigationcontroller iphone

In my application the modal navigationcontroller that I am presenting is going under the current navigationcontroller so I'm not able to view the new navigationbar as it's disappearing under the current one.
I'm presenting the modalview on self and not self.navigationcontroller because self.navigationcontroller doesn't present the modalviewcontroller.
Also how to push a view on this modal navigationcontroller?
I'm using following code in one of my viewControllers:
fullListTopCompanies *fullListTopCompaniesInstance = [[fullListTopCompanies alloc] initWithNibName:#"fullListTopCompanies" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:fullListTopCompaniesInstance];
fullListTopCompaniesInstance.navigationController.navigationItem.title = #"F";
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
[fullListTopCompaniesInstance release];
Can anybody please help?
Thanx in advance.
use animated with transition
according to me you have to change the animation style
i done it before but forgot the code i will post it when i get it
self.navigationController.navigationItem.title = #"F";
Add the above line of code in viewDidLoad method of "fullListTopCompanies" class.
Actually your navigation bar hides because of the modal view and modal view by default doesnt have Navigation bar.To add a navigation bar to modal view you can try the below code:
In Header File
IBOutlet fullListTopCompanies *fullListTopCompaniesInstance;
In Implementation File
UINavigationController *nav = [[UINavigationController alloc] initWithNibName:#"fullListTopCompanies" bundle:nil];
[self presentModalViewController:nav animated:YES];
[nav release];
Also on the "fullListTopCompanies" View Controller dont forget to put a left navigation bar button item for dismissing the modal view.
So add that left bar button (Ideally Cancel Button on navigation bar) and event handler for that left barr button should contain the code
[self dismissModalViewControllerAnimated:YES];
Hope this helps.

popView from UITabBarController inside UINavigationController

I'm building an application based on the Utility template from Xcode, to which I have added some more views. My application structure would be as follows:
MainView (the app menu)
Flip-side view (a calculator)
UINavigationController
Settings view
viewDiDLoad: UITabBarController
- Tab1 view (options)
- Tab2 view (information text)
I can navigate correctly from my MainView to my Flip-side view, which is also the root view of the Navigation Controller. From my Flip-side view, I push a second view of my Navigation Controller (Settings view) that is configured to show an UITabBarController, with two tabs, as soon as it loads (with viewDidLoad).
If I remove the UITabBarController, I can return with no problems to my Flip-side view using "popViewController" from my Settings view. The problem comes if I load the UITabBarController in viewDiDLoad in my Settings view... the tabs work perfectly, but I'm not able to return to my Flip-side view (root view of the Navigation Controller) anymore.
I CAN return if I use the Navigation Bar of the Navigation Controller, but I want to configure my own buttons and have the Navigation Bar hidden.
So far I've tried the following methods:
[self.navigationController popViewControllerAnimated:YES];
[self.navigationController popToRootViewControllerAnimated:YES];
[self.navigationController popToViewController:FlipSideViewController animated:YES];
But they don't seem to work. The first two just do nothing (the screen remains as it was), and the third one does not recognize the "FlipsideViewController" (maybe because it's a delegate of the MainViewController?).
Is there a way to check what is exactly doing the "back" button of the Navigation Bar if I activate it?
Should I be using delegates?
Can I call a popViewController method in my Settings view from any of the two Tab views?
This is my Flip-side view:
- (IBAction)showSettingsView {
SettingsViewController *controller = [[SettingsViewController alloc] initWithNibName:#"SettingsView" bundle:nil];
controller.title = #"Settings";
[self.navigationController pushViewController:controller animated:YES];
[controller release];
}
This is my Settings view:
- (void)viewDidLoad {
[super viewDidLoad];
tabBarController = [[UITabBarController alloc] init];
Tab1ViewController* vc1 = [[Tab1ViewController alloc] init];
Tab2ViewController* vc2 = [[Tab2ViewController alloc] init];
NSArray* controllers = [NSArray arrayWithObjects:vc1, vc2, nil];
tabBarController.viewControllers = controllers;
[self.view addSubview:tabBarController.view];
}
And the method to return in one of the Tab views:
- (IBAction)backFromTab1View {
[self.navigationController popToViewController:FlipSideViewController animated:YES];
}
Thanks very much and sorry if the question is too basic!
I actually solved the problem creating my own UINavigationBar in the Settings view and using:
[self.view insertSubview:tabBarController.view belowSubview:myNavigationBar];
That inserts the rest of the view below the Navigation Bar and I still can use it to configure a button which pops the view and return to the previous screen.
It took me a while to realise the differences between "addSubview" and "inserSubview + belowSubview". Sorry about that!