1

我为我的 iPhone 应用程序创建了一个登录屏幕,如果输入的密码正确,它应该从登录视图更改为主视图,但我不知道如何在 if 语句中更改视图......如果完成了会发生什么到目前为止(不多,我知道)

#import "ViewController.h"
#import "MainViewViewController.h"

@interface ViewController ()

@end

@implementation ViewController



- (IBAction)enterPassword
{
    NSString *passwordString = [NSString stringWithFormat:@"12345"];

    if ([passwordField.text isEqualToString:passwordString]) {

    }

    else {
        UIAlertView *correctPassword = [[UIAlertView alloc] initWithTitle:@"Falsches Passwort" message:@"Dieses Passwort ist falsch! Geben Sie bitte das korrekte Passwort ein!"   delegate:self cancelButtonTitle:@"Zurück" otherButtonTitles:nil, nil];
        [correctPassword show];
    }
}

- (IBAction)switchView:(id)sender {
    MainViewViewController *main = [[MainViewViewController alloc] initWithNibName:nil bundle:nil];
    [self presentViewController:main animated:YES completion:NULL];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

这是整个 ViewController.m 文件,我想将 switchview Action 放入 if 语句中。如何在 if 语句中更改视图。

你能帮我吗,我会很感激谢谢帕特里克

4

1 回答 1

0

好吧,假设您的switchView方法工作正常,只需在 if 语句中调用它。

- (IBAction)enterPassword
{
    NSString *passwordString = [NSString stringWithFormat:@"12345"];

    if ([passwordField.text isEqualToString:passwordString]) {
        [self switchView:nil];
    }
    else 
    {
        UIAlertView *correctPassword = [[UIAlertView alloc] initWithTitle:@"Falsches Passwort" message:@"Dieses Passwort ist falsch! Geben Sie bitte das korrekte Passwort ein!"   delegate:self cancelButtonTitle:@"Zurück" otherButtonTitles:nil, nil];
        [correctPassword show];
    }
}
于 2013-09-11T02:18:22.043 回答