下面是我的代码,我想根据响应字符串执行segue,但不能,有人可以注意我的代码并告诉我什么是错的。我不能执行segue
当我在联系号码输入值时。文本框,应用程序被终止与错误:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't do regex matching on object <UITextField: 0x7faae2079980; frame = (20 353; 280 45); text = ''; 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._%+-][email protected][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 [email protected] 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];
}
}
ucontact被textfiled,你可以对evalute谓词..使用'mobile'或'ucontact.text' –