my situation is as follow:
1) i have rootViewController with navigationController and add button in the toolbar. When i press i push another view using pushViewController method. This view called chooseTypeView which has only tableview with two cells.
2) when any cell is clicked third view will be pushed using the same method to enter some data.
3) now i want when i press the "Done" button in the keyboard to navigate back to rootView controller and dismiss all views in between the current steps and the root view.
i'm using #Protocol to connect views and i could pass information from the last view to the root view but i couldn't dismiss it.
Thanks for all and i hope that i make myself clear.
I could answer this question my self.
In the delegate method i can call [self.navigationController popViewControllerAnimated:YES] which will remove the current view from navigationController views stack.
For SWIFT use the below code:
self.navigationController.popViewControllerAnimated(true)
Related
I am interested in implementing a back button to segue to a previous view controller. I have tried to embed a navigation bar onto the the top of the table view controller but the issue is when I do segue back to the first view controller, by default, Xcode keeps the navigation bar with a back button to go back to the table view controller. Is there a simpler way to implement a segue to go back to the first VC without the navigation bar remaining?
I'm not too sure if this works, but embed your view controllers including the first one inside the navigation controller. That would make all your view controllers with navigation bar above.
On the main view controller (the one you do not want to have the navigation bar), add the line of code inside your viewDidLoad method.
Swift 3:
self.navigationController?.navigationBar.isHidden = true
I found an easy way. On your TableViewController, drag a UIview to the top of the view controller and itll let you insert the view. From there just add your back button
Just assign your "Back" UIBarButtonItem to this method and it should work.
#IBAction func backButtonPressed(sender: AnyObject) {
self.dismissViewControllerAnimated(true, completion: nil)
}
Sounds like a few problems
1) How are you navigating from the first view controller? Is it with Show (Push) if not, you are replacing the first view controller in your stack.
2) Based on your problem, make sure your first view controller is not embedded in a navigation controller
3) As Dylan mentioned, you need to hook your back button to remove the current view controller to return to the first one
4) Extension of (3), how are you segueing back to the first view controller? If you are explicitly navigating to first view controller with your back button handler, it's not actually going back but rather forward and keep the navigation bar.
I have an app which has tab bar controller as main controller. Each tab has a series of views with navigation controller and I normal push and pop those view in stack.
Weird problem is
Case 1 : If I create a UINavigationController and make a new viewController as its root, and present this NavigationController. Within this new navigation stack, I can easily present a view modally and dismiss it without a problem.
Case 2: Now without make a new UINavigationController, I present a view, and when I dismiss a view, the view beneath is behave weirdly. For example, it's the presenting view was UICollectionView, it just scroll back to 1st cell, like it's doing "reload" action and "scrollTo" the first cell. If the presentingView is a pushed view from rootView, it will just popToRoot view, which is definitely not intended.
I didn't have this problem until I implement UITabbarController, so I guess, I should know more that's going on under the hood when presenting a view and dismiss a view in UITabbarController.
I GUESS, when dismiss a view in UITabbarController view, it sort of "RESET" everything to the very first view of it's current tab. I really am not sure it's trure though.
I know it's kind of conceptual, but I can't help to think there must be something critical I am missing here.
I made silly mistake that I sublclass UITabbarController and define navigation controlllers in viewDidAppear instead viewdidLoad, so when I make the window's rootview to tabbar controller, the navigation controllers are not set properly. That's why all punky things happened. It would be nicer if just crash instead of this weird behaviors.
You can try this to go back to your first viewcontroller.
- (IBAction)buttonPressedFromVC2:(UIButton *)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
} // This is going back to VC1.
This method is will be in second viewcontroller.m file. It is button click method.
My app has a main view with a few buttons lined up vertically. Each button is linked to a different view controller. Now, when the user taps on the first button, the first view controller is opened. Within the first view controller, there is a button which takes you directly to the second view controller. When I get to the second view controller, and press the back button, I am taken back to the first view controller. Then I have to press the back button one more time to be taken to the main view controller. What can I do to make the app take me directly to the main view controller from the second view controller, and not through the first view controller? Thanks in advance!
You could bypass the segue_unwind to go back to the main view controller. Just call the performSegueWithIdentifier in the IBAction of the button
Swift
self.performSegueWithIdentifier("SegueIdentifierName", sender: self)
Objective C
[self performSegueWithIdentifier:#"SegueIdentifierName" sender:self];
Here is a similar article as well
What are Unwind segues for and how do you use them?
You can override the back button action to call popToViewController() on the navigationController with the view controller you would like to return to.
There are a lot of answers in SO about this BUT:
[self.navigationController popToRootViewControllerAnimated:YES];
OR
UIViewController *rootViewController = [self.navigationController.viewControllers firstObject];
[self.navigationController pushViewController:rootViewController animated:YES];
Should work just fine.
Next time, TRY to find answers first:
How do I get the RootViewController from a pushed controller?
SWIFT 3.01
self.performSegue(withIdentifier: "SegueIdentifierName", sender: self)
I am making a TabBarController application using the template provided by Xcode and I need to reload the second view controller everytime it is clicked. How do I do this ?
Thanks
Whenever the tab bar switches the view controllers, the viewcontroller viewWillAppear function will be called
So add the code in the viewWillAppear function of the UIViewController
I got an application with a tabbar and a navigation controller for one of the tab view.
The Navigation controller is pushing several views and one of them has a button which permits to add a subview (I am actually displaying a popup message -not an uialert- when pushing that button).
The problem is that I would like now to be able to push a new view controller once I pushed a button in the subview...
I cannot find my navcontroller, even when I use the pushmethod of appdelegate.tabbar.navigationController
Does one of you have easy idea about how to implement that ?
Thanks a lot !
If the button's press action of the second button is being handled in the same UIViewController as the other button's action you should simply be able to use
[self.navigationController pushViewController:newViewController animated:YES];.
If your subview has it's own UIViewController you could add a reference to your first UIViewController or to the navigationController itself and use it that way.