0

So in my App.Delegate I'm doing this -

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.

    self.loginViewController =     [[LoginViewController alloc] initWithNibName:@"LoginView" bundle:[NSBundle mainBundle]];



    UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController: self.loginViewController];
    self.window.rootViewController = navigation;


    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

and in my login controller I'm doing this -

    - (IBAction)login:(UIButton *)sender {
    NSString *username = self.userName.text;
    NSString *password = self.password.text;

    [AccountUtils emailLogin:username password:password useCookie:true callback:^(NSDictionary *loginResponseJSON){
        if([loginResponseJSON count] != 0){
            [self performSelectorOnMainThread:@selector(displaySearchController) withObject:nil waitUntilDone:YES];
           // [self performSelectorOnMainThread:@selector(switchState) withObject:nil waitUntilDone:YES];
        } else {
        //incorrect entry info view here.

        }

    }];

}

- (void) displaySearchController {
    SearchViewController *searchViewController = [[SearchViewController alloc] initWithNibName:@"SearchView" bundle:[NSBundle mainBundle]];
    UINavigationController *navigator = self.navigationController;
    [navigator popViewControllerAnimated: YES];
    [navigator pushViewController: searchViewController animated:YES];
}

If I correctly login, I go to the second controller's view, but at the top I'm still allowed to go 'back' to the login page. I don't want that to happen and I thought this case would be taken care off by the popViewControllerAnimated line. How do I make it so that when I login, I am not allowed to go back to the login page?(in other words, I guess pop the login controller off the navigation controller's stack?)

3 Answers 3

3

If you want just to remove the loginVC you could set the new navigationController as the rootViewController of the AppDelegate after the user has logged in. So you could move the displaySearchController method in the AppDelegate and call this method (from the loginVC) after the user has logged in:

-(void)displaySearchController{
    SearchViewController *searchViewController = [[SearchViewController alloc] initWithNibName:@"SearchView" bundle:[NSBundle mainBundle]];
    UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController: searchViewController];
    self.window.rootViewController=navigation;
}

Otherwise, if you really want the push animation, you can remove the loginVC from the navigationController viewControllers stack in the viewDidAppear of SearchDispalyController:

-(void)viewDidAppear:(BOOL)animated{
  NSMutableArray *stackVCs=[self.navigationController.viewControllers mutableCopy];
  int idx=[stackVCs indexOfObject:self];
  //this remove the previous viewcontroller from the stack
  [stackVCs removeObjectAtIndex:idx-1];
  self.navigationController.viewControllers=stackVCs;
  [super viewDidAppear:animated];
}

Also in the loginVC just before push the searchVC you should call this to hide the back button:
[navigation.navigationItem setHidesBackButton:YES];

0

You don't want to use a UINavigationController with the LoginViewController and you don't want to push the SearchViewController. Instead, use a UINavigationController with SearchViewController and when you display it, make it the rootViewController.

0

Do this to achieve what you want.

  1. Move the displaySearchController method to your AppDelegate.m file
  2. Do declare the displaySearchController method in AppDelegate.h file
  3. Now Define the displaySearchController method in AppDelegate.m file as :

    - (void) displaySearchController {
        SearchViewController *searchViewController = [[SearchViewController alloc] initWithNibName:@"SearchView" bundle:[NSBundle mainBundle]];
        UINavigationController *navigator = [[UINavigationController alloc]initWithRootViewController:searchViewController];
        self.window.rootViewController = navigator;             
    }
    

Call a new local method showNewViewController from your loginController as :

[self performSelectorOnMainThread:@selector(showNewViewController) withObject:nil waitUntilDone:YES];

Now define showNewViewController in your loginController.m file as

-(void)showNewViewController {
    AppDelegate *appDele = [UIApplication sharedApplication].delegate;
    [appDele displaySearchController];
}

Don't forget to import the AppDelegate.h file to your loginController.m

This will certainly help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.