Update: Another solution to this problem would be if the Navigation bar at the root level of the navigation controller could be transparent or not shown. Is there a way to make the Navigation bar at the root level of the navigation controller transparent or not shown?
I have a NIB with a toolbar at the top of my top level UIView and below the toolbar is a tableView. When I use pushViewController on a navigationController to push another UIViewController onto the navigationController, the toolbar is overwritten by the navigation bar. When I pop the current view back to the root view, the toolbar cannot be seen as there is a blank bar across the top. There is now also a gap between the toolbar and the top of the tableView about the size of the toolbar. So the view looks like from the top:
1) shaded blank bar,
2) blank space about the size of a toolbar,
3) tableview
How can I make the toolbar of the top level NIB appear at the top of the UIView after using popViewController?
In the top level view I instantiate a UINavigationController:
self.navigationController = [[UINavigationController alloc] initWithRootViewController:ListsController];
and then in didSelectRowAtIndexPath I push a view controller
ItemsController * Items = [[ItemsController alloc]
initWithNibName:#"Items" bundle:nil] ;
[self.navigationController pushViewController:Items animated:YES];
To get the initial pushed view to display I do the following:
UIView *navView = self.navigationController.view;
CGRect navFrame = navView.frame;
// navFrame.origin.y -= 20;
navView.frame = navFrame;
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
UIWindow *appWindow = appDelegate.window;
[appWindow addSubview:navView];
Any idea how I can get the top level toolbar not to be overwritten when popping back to the top level?
The solution is to make the navigation bar hidden at the root level using:
- (void)viewWillAppear:(BOOL)animated {
[[self navigationController] setNavigationBarHidden:YES animated:YES];
[super viewWillAppear:animated];
[self.table reloadData];
}
Then at the next lower level of the navigation stack, make the navigation bar unhidden:
- (void)viewWillAppear:(BOOL)animated {
[[self navigationController] setNavigationBarHidden:NO animated:YES];
[super viewWillAppear:animated];
[self.table reloadData];
}
Related
I have taken navigation bar from controls and added one right bar button it is also taken from controls my requirement is I just want hide right bar button when view will appear and I have wrote drop down action for right bar button . I have an extra view controller called list view controller in this view controller I have 3 objects when I select one object then it is to be push to main view controller and right bar button is to be visible and when I click on right bar button selected object is to be add in drop down list can any one help me.
[self loadMenu];
[self btn];
self. navigationItem.title = #"sample";
[super viewDidLoad];
appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
I'm a bit confused on what you're asking for, but I believe that all you should have to do is
self.navigationController.navigationItem.rightBarButtonItem.enabled = NO;
This will hide the button because it is set to the not-enabled set....
So, for going from one view to another, just do
[navController pushViewController:viewController animatedYES];
and to go backwards from that view do
[navController popViewControllerAnimated:YES];
now to add it altogether:
// creating UIViewController objects for reference later
View1 *view1 = [[View1 alloc] init];
View2 *view2 = [[View2 alloc] init];
// you are setting the view1 right navigation button in the view1 viewDidLoad
self.navigationController.navigationItem.rightBarButtonItem.enabled = NO;
// now you are pushing to second view
[navController pushViewController:view2 animated:YES];
// now, in the view2 class, where you get the image that sends the
// user back to view 1, just do
[view2.navController popViewControllerAnimated:YES];
// and then wherever you do the pop as shown above, you need to set the
// view1 right bar button to enabled
view1.navigationController.navigationItem.rightBarButtonItem.enabled = YES;
Hope this helps!
I have a tab bar application and when I display a modal view controller, the content screen is offset by about 20 pixels to the top and left. It looks like this:
I'm presenting this view from the child view controller (detail view) of navigation controller (main view) of the tabview.
When I show the view, I'm hiding the tab bar and navigation bar but status bar is kept visible. Adjusting the view to be centered (through Interface Builder's Simulated Interface Elements->View Mode : Center) and changing the view's frame after a call to 'viewDidLoad' in the controller doesn't seem to shift it.
- (void)viewDidLoad {
// this still doesn't cause it to shift
self.view.frame = CGRectMake(0, 20, 320, 460);
}
What's the way to adjust this so that the content area is shown correctly?
I launch the child view like this:
[detailController presentModalViewController:tvc animated:NO];
The app's view controller hierarchy:
Tab view with two child navigation controllers are created in the app delegate and the nav controllers added to the TabBar's view controllers:
tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects:tab1ViewController,
tab2ViewController, nil];
[window addSubview:tabBarController.view];
Each view controllers of the tab is created as a NavigationController with 1 view controller:
// MainViewController inherits from UIViewController
[MainViewController *viewController = [[MainViewController alloc] initWithNib..];
tab1ViewController.viewControllers = [NSArray arrayWithObject:viewController];
A detail view controller is launched with 'pushViewController' as a result of some action on tab1ViewController :
DetailController *detailController = [[DetailController alloc]
initWithNibName:#"DetailView"
bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:detailController animated:YES];
[detailController release];
It's from the detailController that I'm trying to launch the problem controller.
Some things to check right off: is "viewDidLoad" actually getting called?
If so, what is self.view.frame set to after the assignment?
Put an NSLog at the end that prints out the x, y, width, height, and see what's there.
Also, since the trouble vc is modal, it will occupy the entire screen.
"On iPhone and iPod touch devices, the view of modalViewController is always presented full screen."
HTH,
Mike
In my Main Window IB file I have a TabBarController and the first controller is a Navigation Controller. When I push my detail view (after pressing a cell in a table view) I want to push my detail view and display a tool bar instead of the tab bar. The problem is that when I try
tabBar.hidden = visible;
in my detail view controller (viewDidLoad) the tabbar dissapears before the animation between the first view and the detail view is done.
What i want to achieve can be seen in the native photo app when pressing on one of the images from a gallery. There the tabbar moves out with the animation of the first view.
How do I achieve this?
Thanks in advance
check out the 'hidesBottomBarWhenPushed' property on your detail's page subclass of UIViewController
either override this method
- (BOOL)hidesBottomBarWhenPushed
{
return YES;
}
or i'm guessing this would work the same:
self.hidesBottomBarWhenPushed = YES;
as far as showing the toolbar try:
- (void)viewWillAppear:(BOOL)animated
{
[self.navigationController setToolbarHidden:NO animated:YES];
}
and on the way out
- (void)viewWillDisappear:(BOOL)animated
{
[self.navigationController setToolbarHidden:YES animated:YES];
}
I have a tabbar application with a navigation bar. For one of the actions I am instantiating a navigation controller programatically and adding a view with tableview. I want to remove this navigation bar and tableview programatically clicking a button on the new navigation bar. how to do this ?
I tried popview but it is not poping out.
To hide it
[[self navigationController] setNavigationBarHidden:YES];
If you have added a UINavigationController on top of another UIViewController, then from the uiNaviagation controller, you will not be able to remove the navigation bar even if you remove the current view, and all the subview. (the parent uiviewcontroller also get the nav bar)
One way to fix this is, access the app delegate, and remove the top view from the window before
adding the UINavigationController
AppDelegate *dg = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSArray *ar = [[dg window] subviews];
//then remove all the views in ar
//then add uinavcontroller
[[dg window] addSubView:[uinavcontroller view]];
then add UINavigationController, when you want to replace the UInavigationcontroller with the first UiViewController. do the similar steps like above.
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!