tabBarController navigation problem/question - iphone

I have a simple tabBarController application where the user can navigate around 3 views.
In one of the views I have a UIButton that when touched moves the user to a fourth view. the problem is that the new view doesn't have the tab bar navigation visible.
what do I need to do to the fourth view to have it also use the tabBarController feature set.
thanks for any help
here's the code that transitions to the fourth view when a UIButton is touched:
-(IBAction) nextQuestion {
Question2 *q2 = [[Question2 alloc] initWithNibName:#"Question2" bundle:nil];
q2.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:q2 animated:YES];
[q2 release];
}

A modal view controller always takes up the entire screen. Its purpose is to provide a modal interface that does not let the user interact with other parts of the UI until they dismiss the modal view.
To display another view inside a tab, you could make the root controller of that tab a navigation controller. A button tap would then push the Question 2 controller on the nav controller's stack.

Related

iPhone - how do I add a navigation controller to a view?

I currently have an application that does the the following:
S: Loads a view as a login screen to start with.
a: If login is successful I add a terms and conditions screen as a subview
b: If not successful I add a sign up form as a subview
F: Then I load the main part of my app on success of either of the a or b which is the part of the app where there is a navigation controller and a tab bar controller. This is set up in MainWindow.xib
S, a and b also have Nav bars but no navigation controllers as I didn't think I would need navigation control on the login screens.
However it turns out I do, I want to be able to have back navigation from both a and b to the initial login screen.
I have tried several ways of doing this including trying the following answers:
How to add navigation controller in View Based Application in iPhone?
How do you properly set up a secondary view to support a navigation Controller on the iPhone?
how to add navigation controller programatically?
But none of them work for me, they display the new Navigation controller over the login screen and dont load the a or b screens.
I'm guessing this is because I am adding them as subviews to my loginView and this is not the correct way to do this? My code is as follows:
if(self.tcSubViewController == nil){
TCSubViewController *_tcSubViewController = [[TCSubViewController alloc] initWithNibName:#"T&CView" bundle:[NSBundle mainBundle]];
self.tcSubViewController = _tcSubViewController;
[_tcSubViewController release];
}
[self.view addSubview:[tcSubViewController view]];
I'm guessing there's a fundamental flaw in the way my Login flows? I should be able to completely remove the LoginView and then display the Terms and conditions view without having to add it as subview, shouldn't I?
You need to dismiss the navigation controller to go back to.
To dismiss modal view:
1.Easy way: In your modal view in some method that you call to dismiss just add:
[self.navigationController dismissModalViewControllerAnimated:YES];
2.More complex way: Implement and delegate protocol on your modal view and make the view controller that presents the modal view the delegate of it. And in the delegate method dismiss the modal view. I do this way when I need to send data from modal view to the controller that present it.
Reference to this post
Navigation controller philosophy is that you add only navigationController.view as UIWindow subview and it wil manage the rest by itself. You only need to push/pop viewControllers and their corresponding views will be added/removed from screen automatically.
sample code from my current application:
HomeController *homeController = [[[HomeController alloc] init] autorelease];
self.controller = [[[UINavigationController alloc] initWithRootViewController:homeController] autorelease];
self.controller.navigationBarHidden = YES;
[self.window addSubview:self.controller.view];
[self.window makeKeyAndVisible];
and then to push next view you just add next controller:
[self.navigationController pushViewController:newController animated:YES];

How to create a navigation controller based view from a simple uiview?

I have a simple uiviewcontroller with 4 buttons. Every buttonclick event loads a different image on the view. However for the 4th button i want to launch a navigation controller based uiview with a uitableview. The table view can then have 3 levels which define the settings for the application.
On selecting a row in the uitableview on the 3rd level i need to return to my main view with the selected row index.
How can i add a navigation based view which will be launched on a button press event and the first view of the uinavigationcontroller should compose of a back button which will close this navigation view and return to main view.
TIA,
Praveen S
Edit:
My first(home) view does not need a navigation bar. The view launched from the home view should however consist of a navigation bar with back button.
if(nxtv12==nil){
nxtv12=[[v12 alloc] initWithNibName:#"v12" bundle:nil];
}
[self.navigationController pushViewController: nxtv12 animated:YES];
and for coming back to home.
[self.navigationController popToRootViewControllerAnimated:YES];
Create a UINavigationViewController object in the current UIViewController (or use self.navigationcontroller) and push the new UIView into the navigation controller. To come back to the same view, use popToRootViewControllerAnimated in the new UIView class.

Designing an Application with different ViewControllers

after reading a lot of tutorials and threads here on stackoverflow there is one basic question left in my head.
The structure of my App should be the following:
MainMenu - fullscreen without a navigation bar but 2 buttons (button1 and button2)
Page1 - should appear by pressing button1 and should have a navigation bar at the top with a "back"-button to get back to the MainMenu.
Page2 - should appear by pressing button2 without a navigation bar at the top. Page2 should be a UISplitView. There must be a back button somewhere.
(I think this is where the problem starts, a UISplitView can't be presented modally, can it?)
You should be able to add subpages to Page1.
So how can I do that? I don't need executable code but just a hint on how the structure of my app should be. For example where to add the navigation controller, how the MainMenu looks like.
Thanks in advance!
Are you trying to create an Application for iPad?
Your Application's UI sems inconsistent being First View the only view without navigation Bar.
You will be using standard navigation to navigate to page1 from home page. So you will be adding a navigation Controller with Home View Controller as a Root View COntroller with hidden navigation bar.
eg.
-(void)applicationDidFinishLaunching:...
{
HomeViewController * hvc = [[HomeViewController alloc]init];
UInavigationController * nvc = [[UINavigationController alloc]initWithRootViewController:hvc];
nvc.navigationBar.hidden = YES;
[window addSubView:nvc.view];
}
Then on tap of first Button you will be pushing the Page1 View Controller
-(IBActtion)button1Pressed:(id)sender
{
Page1ViewCOntroller * p1vc = [[Page1ViewCOntroller alloc]init];
[self.navigationController pushViewCOntroller:p1vc animated:YES];
}
In viewWillAppear: method of Page1ViewController unhide the NavigationBar and hide it in the viewWillDisappear: method
Your Page 2 needs to be splitViewController.
Now about Split View, Apple says
The split view controller’s view should always be installed as the root view of your application window. You should never present a split view inside of a navigation or tab bar interface.
But as there is no "must" written in the above statement, and since its finally a View Controller in itselt, you should be able to add it on the window or another view.
Try to create a VIewController, with split VIew added on it, and like page1, push the View on the navigation Controller.

adding navigation effect to view based application?

I have created View based application, here i need to navigate between views when button pressed.
so in first view controller i have created action for button pressed.
-(IBAction)loadSecondView:(id)sender
{
SecondView *sView = [[SecondView alloc]initWithNibName:#"SecondView" bundle:nil];
[self.navigationController pushViewController:sView animated:YES];
[sView release];
}
this code is not working, anything i am missing,
i can do this by [self.view addSubview:sView]; but i need navigation effect.
Thanks in advance.
You can't just hook a UIView instance to a navigation controller, that's not how they work.
Take a look at the "Navigation-based Application" template in Xcode, to learn how navigation controllers work.
You can use view controllers while hiding the navigation bar:
[[self navigationController] setNavigationBarHidden:YES animated:NO];
You can then map UIButton instances to selectors that push or pop view controllers, while keeping the navigation bar hidden.
These button instances are subviews of the view controller's view property.
Hiding the navigation bar can help provide the illusion that you are not using a navigation controller, while giving you all the functionality of the navigation controller.
Alex is right, if you create just a "View Based Application" project, no UINavigationController was created so when you push something on it nothing happen, that's normal.
You have to create a UINavigationController and make you main view its rootViewController, then you can push on it a new viewController.
I have got a solution for this,
In View based application the appdelegate file creates object for, view controller and added that view to main window, to do our task, delete the controller in mainwindow.xib and add a UINavigation controller,and create a object to it, and connect outlet to it,and then add this navigation controller view as a sub view,
its work fine.

How i calling UITableViewController in UITabBarController screen using Navigation bar on button click in iphone?

My i have to develop simple window based iphone application.
In my first screen I design the UITabBarController with four TabBarButton.On first Tab screen contains three buttons.
When i click on of the button, the screen should navigate on simple tableView screen.But tableView screen the TabBarController should have be visible. Means simply first replacing with table view and move back to again previous one(The UITabBarController should be visible on all srceen).
Wrap your root view controllers in UINavigationControllers. Then, add the UINavigationControllers to the UITabBarController (so there should be 4 UINavigationControllers, one for each tab). When the button is clicked in the original view controller, do something like:
-(void) buttonClicked {
SimpleTableViewController *tvc = //etc
[self.navigationController pushViewController:tvc animated:YES];
[tvc release];
}