iOS: performSegueWithIdentifier trouble

Wednesday, July 9, 2014

I am pretty new to objective C and iOS, as I am primarily a C++/java developer and I cannot for the life of me get performSegueWithIdentifier to work properly. I am making a simple login system where I have a condition if the status code is not 401 or 403 then go to the main app. Currently in my storyboard I have my main view controller with my textFields and a button to login. I then make a segue from the MainViewController (not the button) with the Identifier MoveToMainApp and style model. in my implementation file for the main view controller I have the following methods:

[self performSegueWithIdentifier:@"MoveToMainApp" sender:nil];

- (IBAction)login:(id)sender {
NSString *username = _usernameTxt.text;
NSString *password = _passwordTxt.text;
_errorLabel.text = @"";
if(username.length > 0 && password.length > 0)
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@""]];
[httpClient setParameterEncoding:AFFormURLParameterEncoding];
NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST"
parameters:@{@"username":username, @"password":password}];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[httpClient registerHTTPOperationClass:[AFHTTPRequestOperation class]];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
// Print the response body in text
NSLog(@"Response: %@", [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
NSInteger statusCode = operation.response.statusCode;
if(statusCode == 401 || statusCode == 403)
_errorLabel.text = @"Invalid credentials";
[self moveToMainApp];

[operation start];

What am I missing here?