Click on ViewController without back button

I am developing an iOS application that contains login / authentication functions - mainly when the user first logs in, when they need to enter the appropriate data for logging in - then they are transferred to the main application screens - subsequent visits to the application that will be automatically checked authenticity.

All of the above works fine - the problem is with the navigation bar - it appears on the main screen in the main part of the application using the "Back" button - I do not want this to be displayed, since they should not be able to return to the login screen after authentication. I assume it uses a root navigation controller that explains the logic, but is there a way to ignore the navigation controller in the login section, so the back button does not appear in the main application.

Below is a screenshot of the structure that will help me explain - the left group of screens is the login process. The right hand is the basic structure of the application.

enter image description here

The code used to switch the screens is as follows:

SWRevealViewController *swRevealController = (SWRevealViewController *)navVC; swRevealController.managedObjectContext = self.managedObjectContext; [self.navigationController pushViewController:controller animated:YES]; 
+6
source share
7 answers

On the screen, which is implemented after logging in, the ViewDidLoad method adds a line to hide the panel button.

 self.navigationItem.hidesBackButton = YES; 

Additionally, you can add the "Exit" option as

 UIBarButtonItem *backBarButton = [[UIBarButtonItem alloc] initWithTitle:@"Logout" style:UIBarButtonItemStyleBordered target:self action:@selector(LogoutClick)]; self.navigationItem.leftBarButtonItem = backBarButton; -(void)LogoutClick { [self showLogoutAlert]; } -(void)showLogoutAlert { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Do you want to Logout ?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Logout", nil]; [alert show]; } - (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { if (buttonIndex == 1) { [self.navigationController popToRootViewControllerAnimated:YES]; } } 
+15
source

Do not press the view controller. Create a new hierarchy with

 [self.navigationController setViewControllers:@[controller] animated:YES]; 
+17
source

Use the modal view manager for the login screen so that perhaps part of it is not part of your navigation manager hierarchy in your navigation root directory by downloading the example code below:

  - (void) viewDidLoad { ...... LoginVC *loginViewController = [LoginVC alloc] init]; loginViewController.parent = self; [self presentViewController: loginViewController animated:YES completion:NULL]; return; } 

You can or cannot reject the modal view from the root - if you do, you will need to call the dismissal procedure from loginViewController, but there are other ways, and you can put the deviation inside the modal view (loginViewController)

  • (void) login_exit: (BOOL) success {[self rejectViewControllerAnimated: YES termination: NULL];

    if! (success) {
    .... send a message (UIAlertview and ask if he wants to try again)} else {} return;}

+3
source

Very simple .. Just go to rootviewcontroller

  SWRevealViewController *swRevealController = (SWRevealViewController *)navVC; swRevealController.managedObjectContext = self.managedObjectContext; //-- I think above lines not needed as per your question [self.navigationController popToRootViewControllerAnimated:YES]; 
0
source

Write this to the viewDidLoad method

 self.navigationItem.hidesBackButton = YES; 
0
source

You need to hide the navigation bar in the ViewController before you click SWRevealViewController using the following line in viewDidLoad

Goal c

 self.navigationController.navigationBarHidden = true; 

Swift

 self.navigationController?.navigationBarHidden = true; 

It will not display the back button in the next view controller, pressed

0
source

This will hide the back button for the first view.

 ClassA* controller = [storyboard instantiateViewControllerWithIdentifier:@"ClassAIdentifier"]; if (controller != nil) { [self.navigationController pushViewController:controller animated:YES]; [controller.navigationItem setHidesBackButton:YES animated:NO]; } 

You MUST hide the navigationItem after clicking, otherwise it will be zero.

0
source

All Articles