i am using the following code to present a modal View but still my navigation bar is hiding behind the status bar.
I can only see half of my Navigation bar ..
Plz point out my error and Suggest me the solution to it.
tabBarController = [[UITabBarController alloc]init ];
UINavigationController *cntrol = [[UINavigationController alloc] initWithRootViewController:tabBarController];
NSArray* controllers = [NSArray arrayWithObjects:firstNav,secondNav,thirdNav,fourthNav,fifthNav, nil];
tabBarController.viewControllers = controllers;
tabBarController.selectedIndex=type;
[self presentModalViewController:cntrol animated:NO];
here firstNav, secondNav,thirdNav, fourthNav and fifthNav are the instatnces of UINavigationController.
TabBarControllers are not meant to live inside navigation controllers, but each tab of a TabBarController can be a NavigationController. I've never tried to display a TabBarController modally but I suppose it should work. Switch the nesting of the TabBarController/NavigationController and it should work.
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.
I'm using Navigation-based Application Template with Core Data. Could anyone please tell me how to and a TabBar on the bottom of the view. I am using UITableView, so If I add UITabBar as subview, the TabBar is moving along with tableView when scrolling. I would like to switch between views with TabBar, first "segment" of TabBar should open the RootView (NavigationBar with TableView),and second some other view.
Now I did this:
UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.viewController = [NSArray arrayWithObject:yourNavigationController];
self.window.rootViewController = tabBarController
[tabBarController release];
that works fine, but how can I add more Items to UITabBar and for each Item some other view? TabBar has now just one Item on which rootView is loaded
Thanks!
Use UITabBarController as your root view controller in your application delegate:
UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.viewController = [NSArray arrayWithObject:yourNavigationController];
self.window.rootViewController = tabBarController
[tabBarController release];
Its simple one, just add UITabbarController to your code and then made the first tab controller to be a navigation controller. And point that navigation controller to your controller which has table view that you want to show.
If you are doing it programmatically you can use this:
FirstViewController *first=[FirstViewController alloc]]init];
UINavigationController *nav=[UINavigationController alloc]]initwithRootViewcontroller:first];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.viewController = [NSArray arrayWithObject:first];
[tabBarController release];
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).
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'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!