I am trying to move to a page after a successful message from my server for a basic login application. Currently when I get a successful log it moves to a black screen like its looking a view controller thats not there. However there is a view controller accioated with the class i am trying to go to. Here is my code so far
if([serverOutput isEqualToString:@"Yes"])
{
NSLog(@"Yes there was a match");
WelcomeScreenViewController *newview =[[WelcomeScreenViewController alloc] init];
[self presentViewController:newview animated:YES completion:nil];
UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"Congrats" message:@"You are authorized"
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alertsuccess show];
`}
Why isn't after i successfully log in it taking me to the welcome screen? Do I need to make the welcome the rootcontroller and then push the log-in screen. Why can't I programmatically move to the view controller with an if statement?
`- (IBAction)loginbuttonpressed:(id)sender {
//Trim white space off username/password
NSString *rawEmail = [_UIEmailTextField text];
NSString *rawPass = [_UIPasswordTextField text];
NSString *trimmedEmail = [rawEmail stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *trimmedPass = [rawPass stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
//Check if text field is empty
if([_UIEmailTextField.text length] > 0 && [_UIPasswordTextField.text length] > 0)
{
NSString *post =[NSString stringWithFormat:@"userName=%@&userPassword=%@",trimmedEmail, trimmedPass];
NSString *hostStr = @"http://server name?";
hostStr = [hostStr stringByAppendingString:post];
NSData *dataURL = [NSData dataWithContentsOfURL: [ NSURL URLWithString: hostStr ]];
NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];
if([serverOutput isEqualToString:@"Yes"])
{
NSLog(@"Yes there was a match");
WelcomeScreenViewController *newview =[[WelcomeScreenViewController alloc] init];
[self presentViewController:newview animated:YES completion:nil];
UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"Congrats" message:@"You are authorized"
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];`
So all of this is run when you hit a log in button. I had it being a seque when you click log in but then if the log in fails it still logs in.