ios - 我无法执行 segue

标签 ios objective-c xcode validation 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 = '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];
    }
    }

最佳答案

对于您的第二个崩溃的问题,这是因为您需要传递 textField.text 而不是 UITextField 对象。所以它应该是 mobile 变量,它包含 textField 的文本而不是 ucontact textField 对象。

[numberTest evaluateWithObject:mobile] 

关于ios - 我无法执行 segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39566543/

相关文章:

ios - 通知每分钟触发 6 次(swift4)

ios - 将 Xamarin.Forms 应用程序部署到物理 iOS 设备时出现 "resource fork, Finder information, or similar detritus not allowed"错误

ios - 延迟一段时间后显示 uipickerview

swift - 当我使用按钮增加单元格高度时,UICollectionView 单元格彼此重叠

objective-c - 将两个 UIImage 堆叠为一个

ios - 如何获取应用程序 iOS UIA 自动化的 Bundle Id

objective-c - xcode:如何隐藏此警告?

iphone - NSArray 的前三项变成 NSString?

ios - 让UIStepper增加5

xcode - 'ld : warning: directory not found for option’