push to a specific view controller regardless of which controller is active

Discussion in 'iOS Programming' started by johnmerlino, Jun 18, 2012.

  1. johnmerlino macrumors member

    Joined:
    Oct 22, 2011
    #1
    Hey all,

    As soon as a user logs in, a timer is set to go off in specific time, if they choose not to remember their login. So regardless of which view controller they are on, after this specific time period, I want them to return to the login screen. Problem is within the LoginViewController, I am not sure how to reference the controller that they are on and to push them back to the login controller:

    Code:
     if(!self.isRememberable){    
                    [NSTimer scheduledTimerWithTimeInterval:30.0 target:self selector:@selector(dismissView) userInfo:nil repeats:NO]; 
                }
    
    
    - (void)dismissView
    {
      User *currentUser = [UserManager currentUser];
        NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@/pages/logout.json?auth_token=%@", RemoteUrl, currentUser.auth_token]];
        ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
        [request startSynchronous];
        
        NSError *error = [request error];
    
        if (error) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:[error description] delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
            [alert show];
        } else {
            NSString *response = [request responseString];
            
            NSDictionary * resultsDictionary = [response objectFromJSONString];
            
            
            NSString * success = [resultsDictionary objectForKey:@"success"];
            
            
            if([success boolValue]){
                currentUser.auth_token = nil;
                [self.navigationController popViewControllerAnimated:YES];
            }
        }
    
        
    }
    
    This line of code just pushes to previous controller of current controller:

    Code:
    [self.navigationController popViewControllerAnimated:YES];
    
    But I want to always return to login controller.

    This here:

    Code:
    [self.navigationController pushViewController:self animated:YES];
    
    raises exception:

    Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing the same view controller instance more than once is not supported (<LoginViewController: 0x7b35990>)'

    thanks for response
     
  2. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    Try searching the headers for popTo and see what turns up.

    Else, read the UINavigationController reference for more possibilities.
     
  3. johnmerlino thread starter macrumors member

    Joined:
    Oct 22, 2011
    #3
    that appeared to have worked
     

Share This Page