Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

johnmerlino

macrumors member
Original poster
Oct 22, 2011
81
0
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
 
Try searching the headers for popTo and see what turns up.

Else, read the UINavigationController reference for more possibilities.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.