When using the modalViewController, I found that that only way to keep a title bar and buttons on the screen that I jump to was to create a navigation controller and set the modalView screen as the rootView of the navigation controller (as below).
userNameViewController = [[UserNameViewController alloc] init];
UINavigationController *cntrol = [[UINavigationController alloc] initWithRootViewController:userNameViewController];
[self.navigationController presentModalViewController:cntrol animated:YES];
[userNameViewController release];
[cntrol release];
Why can't I simply this by using the original viewController as the modalView (as below)?
userNameViewController = [[UserNameViewController alloc] init];
[self presentModalViewController:userNameViewController animated:YES];
Because the navigation bar you usually see belongs to the navigation controller, not to its children view controllers.
You could create your own navigation bar and add it to your controller's view. However, it would require some relayout (and that's probably why it's easier to just recreate a navigation controller).
Related
Is it possible to skip a view in a Navigation Controller? My structure is as follows:
**Main Screen Navigation Controller**
-Main Screen View
**Options Navigation Controller (Modal transition from Main Screen View)**
-Options Screen View
--Sub Options Screen View(Push from Options View)
On the first load of the application, I want to present a "Welcome" UIAlertView that will present the "Sub Options" screen.
Thanks
You'll have to build your navigation stack programmatically and then modally display the UINavigationController. Use the viewControllers property. The last view controller in the passed in array will become the top view controller.
OptionsViewController *ovc = [[OptionsViewController alloc] init];
SubOptionsViewController *sovc = [[SubOptionsViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] init];
nav.viewControllers = [NSArray arrayWithObjects:ovc, sovc, nil];
[self presentModalViewController:nav animated:YES];
Yes. If you read the documentation for UINavigationController, you'll see there's a method called setViewControllers:animated: that you can use to explicitly set the entire stack of view controllers at once.
In my application my first Page is a UITableviewController. Then I add a subView in UIViewcontroller like:
viewcontrollername * prod=[[viewcontrollername alloc]init];
[self.view addSubview:prod.view];
It's fine, but My problem is in UINavigation controller not working in viewcontroller page(doesn't Navigate to another Page). I have implemented it in click event:
prod *login=[[prod alloc]init];
UINavigationController *navCtrl= [[UINavigationController alloc] init];
[navCtrl pushViewController:login animated:YES];
[login release];
And
prod *login=[[prod alloc]init];
[self.navigationController pushViewController:login animated:YES];
[login release];
But it doesn't Navigate to another Page.
Use this code when you init the navigation controller :
UINavigationController *navigationCtrlSlideShowSetting = [[UINavigationController alloc] initWithRootViewController:yourviewcontroller];
Thanks
It looks like navCtrl hasn't been added to the view hierarchy. Either you add it as a subview to the window or make it the rootViewController.
Your first view controller should be the root view controller of the navigation controller.
initWithRootViewController
Alternatively you can add the newly created navigation controller to your viewcontroller.
[self.view addSubview:navCtrl.view];
Once this is done you can push view controllers to the navigation controller.
EDIT:
You need to have a back button in case you do not have a way to come back to main screen. The better option is to use navigation controller for the main screen and go on pushing views onto the stack.
I have a very simple question. I have a view controller. In the view controller, i have added few buttons. On button click I have to start a tab bar controller (each of which has navigation controller).
Code Snippet:
- (IBAction) pushNewsAlertsController:(id)sender {
//Create a navigation controller
UINavigationController *FirstNavController = [[UINavigationController alloc] init] ;
//create the view controller (table view controller)
FirstViewController *firstViewController = [[FirstViewController alloc] init];
[FirstNavController pushViewController:firstViewController animated:YES];
//Create a navigation controller
UINavigationController *secondNavController = [[UINavigationController alloc] init] ;
//create the view controller (table view controller)
SecondViewController *secondViewController = [[SecondViewController alloc] init];
[secondNavController pushViewController:secondViewController animated:YES];
// Set the array of view controllers
tabBarController.viewControllers = [NSArray arrayWithObjects:firstNavController, secondNavController, nil] ;
//Add the tab bar controller's view to the window
[self.view addSubview:tabBarController.view];
}
I am able to add the tabviews and navigation controller. The problem is I am unable to get back to the main view once the button is clicked.
Can anyone guide me on how to get back to the previous view so that I can click other buttons.
In this case, I would consider presenting the tab bar controller modally. It's a cleaner way of organizing your views in the same way the user interface is organized. You can just dismiss the modal presentation to go back to the previous view. Read View Controller Programming Guide for iOS about similar advice and examples.
Not sure if I get what you are trying to do, but if you want the tab bar controller view to disappear again, the only way would be the inverse of
[self.view addSubview:tabBarController.view];
which could be
[tabBarController.view removeFromSuperview];
I must say it looks like an odd construction you're building, but it may work nevertheless.
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).
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.