1

在从我的服务器成功发送基本登录应用程序的消息后,我试图移动到一个页面。目前,当我获得成功的日志时,它会移动到黑屏,就像它看起来不存在的视图控制器一样。但是,有一个视图控制器与我要上的课程相匹配。到目前为止,这是我的代码

    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. 
4

1 回答 1

2

当在 segue 之前测试一个值时,你应该从 viewController 而不是 UIButton 中隐含一个 segue。然后使用 performSegueWithIdentifier 执行添加到控制器的 segue。然后在您的 prepareForSegue 中,您可以测试不同的 segue 并将内容传递给destinationViewController。

以编程方式执行 Segue 并将参数传递给目标视图

于 2013-04-22T20:52:46.743 回答