我为我的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语句中更改Views。
你能帮助我吗,我很感激 谢谢Patrick答案 0 :(得分: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];
}
}