I am having an issue when im using navigation controller.
My program is laid out where I have a start screen (not in the navigation controller) and then when you press a button it sends you to the navigationController and new view.
Is there a way to get back out of the navigation controller back to that home screen using a back button.
OR
if i included the start screen as the root for the navigation controller is there a way to hide the top bar in the view.
The reason i didn't include the start screen originally is because I didn't want the navigation bar on the screen.
Thanks.
For hide the UINavigationBar then use bellow line in viewWillAppear: method of your start screen viewController..
[self.navigationController setNavigationBarHidden:YES];
OR
[self.navigationController setNavigationBarHidden:YES animated:YES];
AND you can go back to previous view and also home screen or parent view with bellow code...
-(IBAction)yourButton_Clicked:(id)sender{
[self.navigationController popViewControllerAnimated:YES];//// For back to Previous view
// [self.navigationController popToRootViewControllerAnimated:YES]; // For Back to home screen or parent view
}
Well there is a very simple method to just hide the UINavigationBar when you want to like this in the ant view :-
[self.navigationController setNavigationBarHidden:YES];
and the in the view in which you would want to show it simply unhide it like this :-
[self.navigationController setNavigationBarHidden:NO];
You can use navigation bar in all screens. But for the screen where you dont want to show it, Just use hide property for navigation bar. That screen will not show navigation bar on top.
[[self navigationController] setNavigationBarHidden:YES animated:YES];
It'll resolve your issue.
- (void) viewWillAppear:(BOOL)animated{
[self.navigationController setNavigationBarHidden:YES animated:animated];
[super viewWillAppear:animated];
}
- (void) viewWillDisappear:(BOOL)animated{
[self.navigationController setNavigationBarHidden:NO animated:animated];
[super viewWillDisappear:animated];
}
By implementing this on your home Screen you can hide the top bar
If you're using storyboard you could create a UIButton and link the view back modally.
Also check out https://stackoverflow.com/a/8348527/401787 for navigating between view controllers.
Actually your requirement are not clearer.
But to hide your navigation controller you can use,
self.navigationController.navigationBarHidden=YES;
and also you can add your custom button on to the navigation bar.
UIBarButtonItem *leftBtn=[[UIBarButtonItem alloc]initWithTitle:#"Back" style:UIBarButtonSystemItemAction target:self action:#selector(backBtnClicked:)];
self.navigationItem.leftBarButtonItem=leftBtn;
and you can right your requirements in the backBtnClicked: method.
you can also navigate to your root level view controller.
U can hide the navigation bar using
self.navigationController.navigationBarHidden = YES;
Add the start screen as sub view to navigation's root view controller.
[self.view addSubview:startScreen.view]
Later Remove it by [startScreen.view removFromSuperview] and set the navigationBarHidden flag to NO.
Related
Hi I am a newbie in iOS
In my project I didn't want to use a Navigation Bar because of the tint effect, so I used a container view to create something similar except for the back button I used an image with a button on the back.
I have used a Container View(connected to a Navigation Controller) to include a label and a button with an image on top of that button. I want the view to go back to the previous view when I click the button (the one inside the container view's navigation controller). I tried the usual [self.navigationController popViewControllerAnimated:YES]; but with no result. How do I execute this task?
If you are using
[self presentViewController:yourVC animated:YES completion:nil];
to present your View Controller, then you should use
[self dismissViewControllerAnimated:YES completion:nil];
to dismiss your present View Controller and to go back to the last View Controller.
the view which you want to push to connect with UINavigation Controller pls clear that you is your app navigation based app, if not pls add it in App Delegate
ViewController *ViewController = [[[ViewController alloc] initWithNibName:#"ViewController" bundle:nil] autorelease];
self.navigationController = [[[UINavigationController alloc] initWithRootViewController:ViewController] autorelease];
hi before i never use navigation controller,
can i use navigation controller like this
consider in my app there is three view (ie main view, first view, second view)
on main view, two UIButton's with button action to move into first view and second view respectively
and to go back to main view, i have to place navigation controller(like back button wiht title) on first view and second view(note:- not navigation controller on main view)
i want to place navigation controller on first view and second view for back to main view
note:- on my main view no navigation controller, navigation controller will be on first and second view used as back buttons and title
can you guide me to the solve this problem
#nandakishore i suggest you to choose the navigation based app in the beginning because you need navigation controller in most of your views(first view and second view)
And you hide the navigation controller when main view didLoad and unhide that when view will dissappear
eg:- In mainview.m
- (void)viewDidLoad {
[super viewDidLoad];
[[self navigationController] setNavigationBarHidden:YES animated:NO];
}
and
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[self navigationController] setNavigationBarHidden:NO animated:NO];
}
now by doing this u will not get navigation controller in mainview but get that in other two views
Hope this may help u....Good luck!!!
When I click the table row, go back to previous view without clicking back button.
I try
[self.navigationController dismissModalViewControllerAnimated:YES];
it's not working. How to dismiss pushViewController ?
dismissModalViewControllerAnimated is used to dismiss a Modal View Controller. These are the view controllers that slide up from the bottom of the screen. An example would be when you tap the button to compose a new email in the Mail app.
If you want the navigation controller to pop back to the previous view controller try using
[self.navigationController popViewControllerAnimated:YES];
Here's a link to the documentation for UINavigationController
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UINavigationController_Class/
[self.navigationController popViewController:YES]
With that line you are dismissing a modal view. That is not the same thing as popping controllers from the navigation controller stack.
You should instead do this:
[self.navigationController popViewControllerAnimated:YES];
This will pop the top controller.
Here is a link to the documentation.
how do you add an overlay view that goes over everything. eg over a tab bar controller, and a navigation controller?
thanks
Find the "top" view in your stack, and add a subview. eg
[self.tabBarController.view addSubview:myView];
The hardest part is finding the topmost view; with a tab bar, it will be its own view.
Add a window. That's what the popup keyboard and UIAlertView do, you can see that in this view dump.
Use a modal view controller. Have a read of this guide:
http://developer.apple.com/iphone/library/featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html
Presenting the view controller itself is easy:
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:addController];
[self presentModalViewController:navigationController animated:YES];
When you enter the search bar handled by a search display controller, it slides the view up and pushes the navigation bar up with it. This is easy enough to do, however, when you click a search result and a new view is pushed on the navigation controller's stack, the navigation bar slides in from the right with the view!
How is this done? If you simply set the navigation bar to hidden or shown, it happens instantly. I can't figure out how it seems to be hidden just for one view controller in the stack!
Many thanks,
Michael
You can animate the transition of the navigation bar. See -setNavigationBarHidden:animated: for more details.
If you need to do this on a per-view controller basis, just override the view controller's -viewDidAppear: and -viewWillDisappear: methods, e.g.:
- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
- (void) viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
The above will hide the navigation bar when this view controller is pushed on top of the navigation stack, and show the navigation bar when the view controller is popped off.
You can call -setNavigationBarHidden:animated: whenever you want, but those two methods are useful for applying lots of UI changes.
-(void)viewDidLayoutSubviews{
[self.navigationController setNavigationBarHidden:NO animated:NO];
}
it will not hide navigation bar.