以编程方式执行故事板Segue

9

大家好,我正在为一个新应用程序开发登录和密码界面,我想有条件地执行一个segue,仅当密码和登录正确时。我在Storyboard中创建了一个Segue,使用“push”样式和“loginMainIdentifier”。实现文件夹的代码如下:

    - (IBAction)pushValidateButton:(id)sender {

    if([loginText.text isEqualToString:@""] || [passwordText.text isEqualToString:@""] )
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Identification" message:@"Veuillez completer l'ensemble des cases SVP" delegate:self cancelButtonTitle:@"Revenir" otherButtonTitles:nil];
        alert.alertViewStyle = UIAlertViewStyleDefault;
        [alert show];
    }

    if(![loginText.text isEqualToString:@""] && ![passwordText.text isEqualToString:@""])
    {
    //creation of the request
        NSMutableString *string = [[NSMutableString alloc] initWithCapacity:100];
        NSString *string01 = @"http://89.82.227.112/Vico/login.php?l=&m="; 


        [string appendFormat:string01];
        NSString *string02 = loginText.text;
        NSString *string03 = passwordText.text;

        [string insertString:string03 atIndex:41];
        [string insertString:string02 atIndex:38];

        NSURLRequest *request01=[NSURLRequest requestWithURL:[NSURL URLWithString:string]cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];

    //create the connection and start loading data

        NSURLConnection *connection01 = [[NSURLConnection alloc] initWithRequest:request01 delegate:self];
        if(connection01)
        {
        //Create NSMutableData to receive data
        //receiveddata is an instance declared elsewhere
        receivedData = [NSMutableData data];
        }
    }
    [self performSegueWithIdentifier:@"loginMainSegue" sender:self];
}

我不理解为什么代码结尾加上[self performSegueWithIdentifier:@"loginMainSegue" sender:self],却无法运行。

有人知道如何在登录和文本都填写的情况下才执行segue吗?

谢谢

Victor

1个回答

5

请检查名称的拼写是否正确(您在代码中写了loginMainIdentifier,然后是loginMainSegue)。

还要检查这个segue是否从整个viewController连接到目标viewController。


非常感谢,拼写错误只是在我的帖子中。但我将segue的连接更改为整个ViewController,现在它可以工作了。再次感谢。维克多 - Vico la patate

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接