[英]Validating more then on text field in IOS7
嗨我正在验证多一个文本字段它不能正常工作,例如,如果有4个字段意味着它的验证工作在3个字段上它不工作在第4个我尝试使用其他如果在目标c中我们如何正常使用c和其他语言但其他如果不可用请告诉我如何解决这个问题。
- (IBAction)reg:(id)sender {
if ([name.text length] > 25 && [city.text length] > 25) {
UIAlertView *alert1 = [[UIAlertView alloc]initWithTitle:@"Message" message:@"pls enter less then 25 character in name and city" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
[alert1 show];
[alert1 release];
}
if ([self validateEmail:[email text]] != 1) {
UIAlertView *alert1 = [[UIAlertView alloc]initWithTitle:@"Message" message:@"Pls enter valid email id" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
[alert1 show];
[alert1 release];
}
if ([self phonevalidate:[phone text]] != 1) {
UIAlertView *alert1 = [[UIAlertView alloc]initWithTitle:@"Message" message:@"Pls enter only 10 numbers" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
[alert1 show];
[alert1 release];
}
if ([name.text length] < 1 && [city.text length] < 1) {
UIAlertView *alert1 = [[UIAlertView alloc]initWithTitle:@"Message" message:@"pls fill the empty field" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
[alert1 show];
[alert1 release];
}
else {
pollpoliticalViewController *pollVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"PollPoliticalVCID"];
//pollpoliticalViewController *vc2 = [[pollpoliticalViewController alloc] init];
[self presentViewController:pollVC animated:YES completion:nil];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Thanks For The Registration" delegate:self cancelButtonTitle:@"ok" otherButtonTitles: nil];
[alert show];
[alert release];
}
}
在上面的代码中,第一个验证不起作用请告诉我是否有另一种方法来验证多个文本字段,或者请告诉我在上面的代码中我做错了。
谢谢。
......其他如果不可用......
else if
在Objective C中可用。
if () {
} else if () {
} else if () {
} else {
}
http://en.wikipedia.org/wiki/Objective-C
Objective-C是C之上的薄层,而且是C的严格超集; 可以使用Objective-C编译器编译任何C程序,并在Objective-C类中自由包含C代码。[7]
Objective-C从Smalltalk派生其对象语法。 非面向对象操作的所有语法(包括原始变量,预处理,表达式,函数声明和函数调用)都与C的语法相同,而面向对象特性的语法是Smalltalk的实现 - 风格的消息。
使用else if语法
- (IBAction)reg:(id)sender {
if ([name.text length] > 25 && [city.text length] > 25) {
UIAlertView *alert1 = [[UIAlertView alloc]initWithTitle:@"Message" message:@"pls enter less then 25 character in name and city" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
[alert1 show];
[alert1 release];
} else if ([self validateEmail:[email text]] != 1) {
// Show Alert
} else if ([self phonevalidate:[phone text]] != 1) {
// Show Alert
} else if ([name.text length] < 1 && [city.text length] < 1) {
// Show Alert
} else {
// Everything passed
pollpoliticalViewController *pollVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"PollPoliticalVCID"];
[self presentViewController:pollVC animated:YES completion:nil];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Thanks For The Registration" delegate:self cancelButtonTitle:@"ok" otherButtonTitles: nil];
[alert show];
[alert release];
}
}
或者,像这样添加一些回报:
- (IBAction)reg:(id)sender {
if ([name.text length] > 25 && [city.text length] > 25) {
UIAlertView *alert1 = [[UIAlertView alloc]initWithTitle:@"Message" message:@"pls enter less then 25 character in name and city" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
[alert1 show];
[alert1 release];
return;
if ([self validateEmail:[email text]] != 1) {
// Show Alert
return;
}
if ([self phonevalidate:[phone text]] != 1) {
// Show Alert
return;
}
if ([name.text length] < 1 && [city.text length] < 1) {
// Show Alert
return;
}
// Everything passed
pollpoliticalViewController *pollVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"PollPoliticalVCID"];
[self presentViewController:pollVC animated:YES completion:nil];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Thanks For The Registration" delegate:self cancelButtonTitle:@"ok" otherButtonTitles: nil];
[alert show];
[alert release];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.