在从我的服务器成功发送基本登录应用程序的消息后,我试图移动到一个页面。目前,当我获得成功的日志时,它会移动到黑屏,就像它看起来不存在的视图控制器一样。但是,有一个视图控制器与我要上的课程相匹配。到目前为止,这是我的代码
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];
`}
为什么我成功登录后没有将我带到欢迎屏幕?我是否需要将欢迎设置为 rootcontroller,然后推送登录屏幕。为什么我不能使用 if 语句以编程方式移动到视图控制器?
`- (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.