2013-09-11 77 views
1

我爲我的iPhone應用程序創建了一個登錄屏幕,如果輸入的密碼正確,但是我不知道如何在if語句中更改視圖,它應該從登錄視圖更改爲主視圖... 這裏如果是迄今爲止做了什麼(is'nt多,我知道)登錄更改視圖

#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行動進入if語句。如何在if語句中更改視圖。

能否請你幫我,我會理解 感謝帕特里克

回答

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]; 
    } 
} 
+0

非常感謝你!幫了我很多 –

+0

很高興幫助!你可以upvote並接受我的回答,爲了將它從未回答的部分中刪除:) –

+1

我不得不聲望投票......但我接受了它:) –