I have a navigation controller as a root view to the home view then a sign in view then the main view. When I sign in and segue to the main view using
vc.performSegueWithIdentifier("toMenuView", sender: nil)
I can slide back to the sign in view. I don't want that. How can I segue to the main view without having access to going back unless the user taps the sign out button and then goes back to the home view without again having access to go "back" to the main view?
For gesture recogniser to swipe back to previous page.
self.navigationController.interactivePopGestureRecognizer.enabled = false
If you have a navigation bar, you might need to hide it too. Else you can also hide the back button by:
self.navigationController.navigationItem.backBarButtonItem.enabled = false
Related
I know there are a lot of posts about this but my problem is a bit different. I have a Tab Bar Controller with multiple views and one of the views is the Login View, if the user does Login it should change the view to present the User menu.
At the same time i need to keep the Tab Bar menu visible, so i can't use modal since it will loose the reference to the Tab Bar Controller.
So i ended up using a Navigation Controller where i just push the User Menu view into the stack (not the best way but it works).
The problem is, if the user double click on the Login Bar it will load the Login View, and i don't want this to happen.
On this example, if the user clicks on the Login button it will go to the Blue view, but if the user double click on the Feature Button on the Tab Bar Menu it will go to the red view.
Since my solution does not work how can i achieve what i want? If the user press the Login button it will ONLY show the Blue view until he press the Logout button.
[Edit]
Here is the code to show the blue view:
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let ViewController = storyBoard.instantiateViewController(withIdentifier: "userViewID") as! UserViewController
self.navigationController?.pushViewController(ViewController, animated: true)
Ok i ended up checking if the Navigation Controller had more than one child (for the red one) and removing the first child from the navigation array so it could dealloc it and show only the one i wanted.
override func viewWillAppear(_ animated: Bool) {
if((self.navigationController?.viewControllers.count)! > 1)
{
self.navigationController?.viewControllers.removeFirst()
}
}
The reason i ended up doing this was because clicking 2x on the Tab Bar item it would bring me to the red view even if i had already pushed the blue view to the Navigation array.
I have been trying to properly setup a navigation bar in one of my View Controllers for an hour now and have not found any working solutions.
I control-clicked on a button on my app's initial view controller(1st VC) and dragged to another view controller(2nd VC) and selected "modal" as the action segue.
I then added a navigation bar item to my 2nd view controller.
When I run my app on my iPhone, I can tap on the button on my app's initial screen and it will take me to my 2nd VC, and the 2nd VC does display the navigation bar, but the navigation bar does not have the default iOS 7 back arrow to let me go back to the app's initial VC.
I was under the impression that this could be setup exactly like I did above and that the back button functionality would be included by default.
Am I completely lost? Do I need to further customize navigation bar programmatically or with a tick box in the attributes inspector? Is "modal" the wrong action segue option?
I basically just want to have navigation bars at the top of a couple of my VC's so that the user can easily get back to the app's initial screen.
Thanks for the help.
Since you are presenting your second screen (2nd VC) as MODAL from your first screen (1st VC), you will not see the back arrow button on navigation bar. Your understanding about back button works for Navigation view controllers (push segue). For MODAL you need to put a cancel button on second VC's Nav bar and put a dismiss action for that.
My iPhone app has a tab bar controller, and one of the tabs is a navigation controller. When the user double taps on the tab, it causes the navigation controller to pop back to the root view.
My problem is that some of the views in my navigation hierarchy have a specific bar button in their navigationItem associated with that view. So I'm programmatically setting the rightBarButtonItem based on what view was pushed to the navigationController. When the double-tap happens, it pops back to the root view, but not to the right button. The button seems to stay the same as the last view popped that had its own specific button.
So I have a mismatch of the root view with a bar button that goes with another view.
Is there a way to detect when the double tap action occurs? In that case I could reset the buttons on the nav bar to the correct ones. I tried doing it in viewWillAppear/viewDidAppear/viewDidLoad methods, but these don't seem to be called when the tab bar double tap happens.
The safest way to ensure that you always have the right button independent of how the view was made visible (e.g., by popping a child view controller, or by double-tapping the tab bar) is to set the button each time the view becomes visible. Thus, in your root view controller:
-(void)viewWillAppear {
//check button, change if desired
}
I have a navigation controller-based app in which I would like to temporarily disable the navigation controller (top left button) at a certain point in the app so that the user can't get out of the view while I'm uploading a file. Is there a way to disable the "back" button so that users can't get out of the view?
You could hide the navigation bar entirely with
- (void)setNavigationBarHidden:animated:
in the appropriate views.
I don't know of an Apple-approved way to disable or otherwise interact with the back button.
In the view controller pushing into the view where you want to hide the back button (NOT in the view controller where you want the back button hidden), do:
self.navigationItem.hidesBackButton = YES;
I have a simple tableview that navigates to a detailed view with a navigation controller. In the detailed view I need to create a button which when pressed isolates all other buttons displayed on the screen including the navigation controller back button. I know how to get the invisible button to cover most of buttons the screen but I can't get it to cover the navigation controller back button as this has been created in the parent view. How do I pop it over the top of the navigation controller from the detail view?
You can insert the button as a direct subview of the key window.
[[UIApplication sharedApplication].keyWindow addSubview:theButton];
(why not use an UIAlertView or UIActionSheet?)