簡體   English   中英

控制兩個viewController之間的過渡

[英]Control the transition between two viewControllers

我是Objective-c的新手,最近開始使用Xcode制作iOS應用程序。 我正在制作一個具有兩個視圖控制器的登錄應用程序。 看起來像這樣: http : //imgur.com/W3nxMEG

現在我的問題是,只有在以下情況下,我才是進入第二個ViewController的應用程序:1)填寫了文本字段2)密碼匹配

那就是我寫的代碼。 我找不到基於某些約束來控制viewControlled之間的過渡的任何命令:

(IBAction)loginButton:(id)sender {

BOOL passMatch, emptyUser, emptyPass, emptyrePass;

passMatch = [password isEqualToString:reEnter];

emptyUser = [username isEqualToString:@""];

emptyPass = [password isEqualToString:@""];

emptyrePass = [reEnter isEqualToString:@""];


if (emptyPass || emptyUser || emptyrePass){

    UIAlertView *error=[[UIAlertView alloc] initWithTitle:@"Ooops!" message:@"You must complete all the fields " delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [error show];

}

else{

    passMatch = [password isEqualToString:reEnter];

    if (passMatch){


       UIAlertView *pass=[[UIAlertView alloc] initWithTitle:@"Success!" message:@"Passwords match " delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [pass show];

    } else{

        UIAlertView *error=[[UIAlertView alloc] initWithTitle:@"Ooops!" message:@"Passwords dont match " delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [error show];
    }
}

如果有人可以幫助我解決這個問題,請多謝

首先確保您的storyBoard中的UITextFieldUIButtonLoginViewController.h的屬性掛鈎

它看起來像這樣:

LoginViewController.h

@interface LoginViewController : UIViewController

@property (strong, nonatomic) IBOutlet UITextField *password;

@property (strong, nonatomic) IBOutlet UITextField *username;

// and so on..

// for your button
@property (strong, nonatomic) IBOutlet UIButton *loginButton;

@end

LoginViewController.m

@implementation LoginViewController


-(IBAction)loginButton:(id)sender 
{

    // you can enable/disable your button here also, by:
    // UIButton *senderButton = (UIButton *)sender;
    // senderButton.enabled = YES/NO;

    // i'm just using .length because i trust numbers more that the @""
    NSString *errorMessage;

if (self.username.text.length == 0)
    errorMessage = @"username is required";

else if (self.password.text.length == 0)
    errorMessage = @"password is required";

else if (self.reEnter.text.length == 0)
    errorMessage = @"please confirm your password";

else if (self.password.text.length == 0 || self.username.text.length == 0 || self.reEnter.text.length == 0)
    errorMessage = @"You must complete all the fields";

if (errorMessage.length > 0)
{
    UIAlertView *error=[[UIAlertView alloc] initWithTitle:@"Ooops!" message:errorMessage delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [error show];
}
else
{
    if ([self.username.text isEqual: @"youUsername"] && [self.password.text isEqual: @"youPassword"] && [self.password.text isEqual: self.reEnter.text])
    {
        UIAlertView *pass=[[UIAlertView alloc] initWithTitle:@"Success!" message:@"Login successful" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [pass show];

        //presentYourSecondViewController         
        //[self presentViewController:(UIViewController) animated:(BOOL) completion:nil];
        //[self.navigationController pushViewController:(UIViewController)animated:(BOOL)];
    }
    else
    {
        UIAlertView *error=[[UIAlertView alloc] initWithTitle:@"Ooops!" message:@"Login failed" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [error show];
    }
}


    /* Your code...


    BOOL passMatch, emptyUser, emptyPass, emptyrePass;

    passMatch = [password isEqualToString:reEnter];

    emptyUser = [username isEqualToString:@""];

    emptyPass = [password isEqualToString:@""];

    emptyrePass = [reEnter isEqualToString:@""];

    if (emptyPass || emptyUser || emptyrePass){

        UIAlertView *error=[[UIAlertView alloc] initWithTitle:@"Ooops!" message:@"You must complete all the fields " delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [error show];

    }

    else
    {

        passMatch = [password isEqualToString:reEnter];

        if (passMatch){

            UIAlertView *pass=[[UIAlertView alloc] initWithTitle:@"Success!" message:@"Passwords match " delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [pass show];

        } else{

            UIAlertView *error=[[UIAlertView alloc] initWithTitle:@"Ooops!" message:@"Passwords dont match " delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [error show];
        }
    }
    */
}

@end

您的狀況沒有問題,我想我剛結束。.無論如何希望我能幫助您,為編碼愉快而歡呼..

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM