1

ユーザー入力を検証する単純なアプリを作成しました (NULL または定義された長さより長いかどうか)。検証が失敗した場合は検証エラー メッセージを返し、それ以外の場合は別のページにリダイレクトする必要があります。

ただし、アプリはすべてのシナリオの最初の条件 (ユーザー名が空) のメッセージのみを返します。(ユーザー名が入力され、パスワードが空であるなど)

m ファイル:

- (IBAction)doLogin {

 if(uname.text==NULL) {
     UIAlertView *err1 = [[UIAlertView alloc]
                                     initWithTitle:@"Required field!" message:@"Username is empty." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
     [err1 show];
 NSLog(@"%@",uname.text);         
 }

 else if(passw.text==NULL) {
     UIAlertView *err2 = [[UIAlertView alloc]
                               initWithTitle:@"Required field!" message:@"Password is empty." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
     [err2 show];
 NSLog(@"%@",passw.text);
 }

 else if (uname.text.length < 6)
 {
     UIAlertView *err3 = [[UIAlertView alloc]
                               initWithTitle:@"Invalid!" message:@"Enter a username longer than 6 chars." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
     [err3 show];
 NSLog(@"%@",uname.text);
 }

 else if (uname.text.length < 8)
 {
     UIAlertView *err4 = [[UIAlertView alloc]
                               initWithTitle:@"Invalid!" message:@"Enter a password longer than 8 chars." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
     [err4 show];
 NSLog(@"%@",uname.text);
 }
 else {
     /*UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Thank you" delegate:self cancelButtonTitle:@"Close" otherButtonTitles:@"OK", nil];
     [alert show];*/
UIViewController* flipViewController = [[UIViewController alloc] initWithNibName:@"flip" bundle:[NSBundle mainBundle]];
[self.view addSubview:flipViewController.view];

}
4

3 に答える 3