下面是我的代码,我想根据响应字符串执行segue,但是不能,有人可以看出我的代码并告诉我出了什么问题。
当我在联系号码中输入值时textfield,app正在以错误终止:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't do regex matching on object <UITextField: 0x7faae2079980; frame = (20 353; 280 45); text = '9876543210'; clipsToBounds = YES; opaque = NO; autoresize = W+TM+BM; gestureRecognizers = <NSArray: 0x7faae2097250>; layer = <CALayer: 0x7faae2083bd0>>.'
我试过的代码:
- (IBAction)Register:(id)sender {
if ((uname.text.length==0)&&(uemail.text.length==0)&&(ucontact.text.length==0)&&(upwd.text.length==0)&&(confirmpwd.text.length==0)){
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Can not Register"
message:@"All the Fields are Mandatory"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:@"Cancel", nil];
[alert show];
}
else{
NSString *emailString = uemail.text;// storing the entered email in a string.
//Regular expression to checl the email format.
NSString *emailReg = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest=[NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailReg];
if(([emailTest evaluateWithObject:emailString]!=YES)||[emailString isEqualToString:@""])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Warning" message:@"Enter your email in abc@example.com format." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
uemail.text = @"";
return;
}
}
NSString *mobile=ucontact.text;
NSString *numberRegEx = @"([0-9]{10})";
NSPredicate *numberTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", numberRegEx];
if ([numberTest evaluateWithObject:ucontact] != YES||[mobile isEqualToString:@""])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Warning" message:@"Enter a Valid Number." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
uemail.text = @"";
return;
}
if ((upwd.text)!=(confirmpwd.text)) {
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Password Do Not Match"
message:nil
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:@"Cancel", nil];
[alert show];}
NSURL *url = [NSURL URLWithString:@"http://108.179.246.128/connectme/service/registration.php"];
NSMutableURLRequest *rq = [NSMutableURLRequest requestWithURL:url];
[rq setHTTPMethod:@"POST"];
NSString *params=[NSString stringWithFormat:@"name=%@&email=%@&mobile=%@&passwrd=%@",self->uname.text,self->uemail.text,self->ucontact.text,self->upwd.text];
NSData *postData = [params dataUsingEncoding:NSASCIIStringEncoding];
[rq setHTTPBody:postData];
NSURLResponse *response;
NSError *error;
NSData *urlData = [NSURLConnection sendSynchronousRequest:rq returningResponse:&response error:&error];
NSString *str=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding]; NSLog(@"Login response:%@",str); //getting response
// [self performSegueWithIdentifier:@"activity" sender:self];
if([str isEqual: @"Successfully Registered"])
{
[self performSegueWithIdentifier:@"login" sender:self];
}
else if([str isEqual:@"Sorry Email address already taken"])
{
UIAlertView *alertit=[[UIAlertView alloc] initWithTitle:@"Can not Register"
message:@"Email Address already Taken"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:@"Cancel", nil];
[alertit show];
}
}
答案 0 :(得分:1)
对于崩溃的第二个问题,这是因为您需要传递textField.text
而不是UITextField
对象。所以它应该是包含textField文本而不是mobile
textField对象的ucontact
变量。
[numberTest evaluateWithObject:mobile]