how to work without with navigation controller - iphone

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!!!

Related

iOS UINavigationController

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.

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.

tabBarController navigation problem/question

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.

Problem dismissing multiple modal view controllers

I am having trouble getting my modal view controllers to display properly. I have a parent view controller that is the delegate for modal view A. In modal view A I am presenting modal view B, and having the delegate dimiss modal view A.
When modal view B appears it seems to display but the screen dims, and the UI locks up, but the app doesn't crash. I set animation settings to NO and I am still getting the same issue.
Order of events:
Parent View show Modal View A
Modal View A shows Modal View B in Modal View A controller
Parent View dismisses Modal View A in Modal View A controller via delegation
This is where my UI hangs, I can see Modal View B but can't click on it, or do anything
You could use this
[[[self presentingViewController] presentingViewController] dismissModalViewControllerAnimated:YES];
A modal view controller must have a parent view controller in order to display. If you dismiss the parent view controller ("modal view A", in your case), behavior will be unpredictable.
If you're certain that nested modal view controllers are what you really want, you'll need to dismiss them in reverse order; wait until you're done with "B", then dismiss "B", then dismiss "A".
If you don't need the modal presentation style, you would be better off using a UINavigationController to maintain your stack of view controllers.
Update: here is how I would rearrange your order of events. Presented as code for clarity.
[parentView
presentViewController:modalViewControllerA
animated:YES]
[modalViewControllerA
presentViewController:modalViewControllerB
animated:YES]
[modalViewControllerA
dismissModalViewControllerAnimated:YES]
[parentView
dismissModalViewControllerAnimated:YES]
Solved by having my parentViewController act as the delegate. Here is my order:
[parentView presentViewController:modalViewControllerA animated:YES]
[parentView dismissModalViewControllerAnimated:YES]
[parentView presentViewController:modalViewControllerB animated:YES]
//Modal B dismisses himself
In my delegate method, I needed to make sure that I dismissed Modal A before presenting Modal B
For iOS 6+ and - presentViewController:animated:completion:
[[[self presentingViewController] presentingViewController] dismissViewControllerAnimated:YES completion:nil];
in Swift 2.1
you can try
self.presentingViewController?.presentingViewController?.dismissViewControllerAnimated(true, completion: nil)
works for me
View A -> View B -> View C
Apply this code in view C , you will be landing to View A
I have a main view and need to show a modalview1 where a button present a modalview2. Looks the same you needed.
But there is a button in the modalview2 which forwards to the main view.
So the solution is:
Main view presents UINavigationController with modalview1 as rootController. Then modalview1 present modalview2 by "[self.navigationController modalview2 animated:YES];".
When modal2 needs to forward to the main view, just make "[self.parentViewController dismissModalViewControllerAnimated:YES];" and UINavigationController is hidden.
Hope it's clear.
Simple:
Dismiss all views:
[self dismissModalViewController animated:YES];
[self dismissModalViewController animated:YES];
[self dismissModalViewController animated:YES];
[self dismissModalViewController animated:YES];
(one for each added modal view)
then present a new modal view controller
may be after long but.. I am in same problem and this is the only post with some answer.
I am not getting what you mean by setting delegate of a parentViewController to self is not allowed .
what I am doing right now is
[self presentModalViewController:ViewControllerA animated:YES];
[self dismissModalViewControllerAnimated:YES];// inside ViewControllerA
[self presentModalViewController:ViewControllerB animated:YES];
[self dismissModalViewControllerAnimated:YES];// inside ViewControllerB
Problem is after viewControllerA , viewControllerB view is not presenting.
Thanks,
Apple document about dismiss(animated:completion:) method.
In section Discussion, it said:
any intermediate view controllers are simply removed from the stack.
If you present several view controllers in succession, thus building a stack of presented view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. When this happens, only the top-most view is dismissed in an animated fashion; any intermediate view controllers are simply removed from the stack. The top-most view is dismissed using its modal transition style, which may differ from the styles used by other view controllers lower in the stack.
In other words, if the view controller stack like following
Root -> A -> B -> C -> D ... -> Z
D calls dismiss method, all view controllers behide D, ex: (E ... Z), will be removed from the stack.

How does the search display controller hide the navigation bar?

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.