无法执行segue

时间:2017-06-05 06:52:34

标签: ios objective-c xcode

在会话块工作正常,但当我试图移动到下一个Viewcontroller我得到thread1:信号SIGABRT ..实际上我试图从服务器获取请求并使用回复执行以下代码

    - (IBAction)submitb:(id)sender{
    if(_otptf.text==self.otpStr && _otptf.text>0){
    NSString *post = [NSString stringWithFormat:@"phone=%@",self.stri1];
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    //Next up, we read the postData's length, so we can pass it along in the request.
    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
    // Now that we have what we'd like to post, we can create an NSMutableURLRequest, and include our postData
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    [request setURL:[NSURL URLWithString:@"http://test.kre8tives.com/barebon/customer_checkapi.php"]];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setHTTPBody:postData];
    NSLog(@"the data Details is %@", post);
          //   And finally, we can send our request, and read the reply by creating a new NSURLSession:
    NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
    static NSURLSession* sharedSessionMainQueue = nil;
    if(!sharedSessionMainQueue){
        sharedSessionMainQueue = [NSURLSession sessionWithConfiguration:nil delegate:nil delegateQueue:[NSOperationQueue mainQueue]];
    }

    [[sharedSessionMainQueue dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
        NSString *requestReply = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; // this is json string
    //  NSError *error;
        NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; // you need to convert to dictionary object
        NSLog(@"Req cust:%@",requestReply);
        NSLog(@"requestReply cust: %@", jsonDict);
        self.tmpv1=[jsonDict valueForKey:@"success"] ;
        self.strv1=self.tmpv1;
        NSLog(@"tmp storage inside block:%@",self.tmpv1);
        if (!error) {
            if([self.tmpv1 isEqualToString:@"%@"],"0"){
                          [self performSegueWithIdentifier:@"x2" sender:self];
                //[self performSegueWithIdentifier:@"x2" sender:self];
                }
            if([self.tmpv1 isEqualToString:@"%@"],"1"){
                    [self performSegueWithIdentifier:@"b2" sender:self];
                }
        }
    }] resume];
   // [self navi];

}
else{
/* what ever */
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Inputs Found or Incorrect Otp!!"
                                                message:@"Please check your input!!."
                                               delegate:self
                                      cancelButtonTitle:@"OK"
                                      otherButtonTitles:nil];
[alert show];
    }
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(nullable      id)sender{
    if ([[segue identifier] isEqualToString:@"x2"])
   {
    ProfileViewController *loadCtr = (ProfileViewController *)segue.destinationViewController;
    //loadCtr.mobilestrp = self.stri1;
}

else if ([[segue identifier] isEqualToString:@"b2"])
{

}

}

这是我的日志

2017-06-05 12:14:32.884 MenuBar[1496:103465] the data Details is phone=9047038606
2017-06-05 12:14:33.726 MenuBar[1496:103531] requestReply: {
    otp = 828712;
    success = 1;
}
2017-06-05 12:14:33.727 MenuBar[1496:103531] tmp storage inside block:828712
2017-06-05 12:14:33.728 MenuBar[1496:103531]  storage:828712
2017-06-05 12:14:33.729 MenuBar[1496:103531] tmp storage:828712
2017-06-05 12:14:33.738 MenuBar[1496:103465] 9047038606
2017-06-05 12:14:45.069 MenuBar[1496:103465] the data Details is phone=9047038606 
2017-06-05 12:14:49.919 MenuBar[1496:103465] Req cust:{"success":0}
2017-06-05 12:14:52.373 MenuBar[1496:103465] requestReply cust: {
    success = 0;
}
2017-06-05 12:14:52.715 MenuBar[1496:103465] tmp storage inside block:0
2017-06-05 12:28:08.486 MenuBar[1520:108818] -[WelcomeViewController setCustid:]: unrecognized selector sent to instance 0x7ff98f908790
2017-06-05 12:28:08.491 MenuBar[1520:108818] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-   [WelcomeViewController setCustid:]: unrecognized selector sent to instance   0x7ff98f908790'
    *** First throw call stack:
   (
    0   CoreFoundation                      0x000000010ba31b0b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x000000010b126141 objc_exception_throw + 48
    2   CoreFoundation    

提前感谢您的建议!!

4 个答案:

答案 0 :(得分:2)

您没有检查prepareForSegue方法中的 segue标识符

检查如下:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(nullable    id)sender{
  if([segue.identifier isEqulaToString: @"x2"]){
    //x2 view controller settings 
  }
  else if([segue.identifier isEqulaToString: @"b2"]){
    //b2 view controller settings 
  }
}

使用此功能,您可以设置特定的视图控制器及其属性。

答案 1 :(得分:2)

segue 定义了两个视图控制器之间的转换。在您的情况下,segue呈现的WelcomeViewController没有属性custid,因此最好使用segue identifier进行检查。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

       if ([segue.identifier isEqualToString:@"YOUR_SEGUE_IDENTIFER"]) {
           //YOUR Code Here
           ProfileViewController *loadCtr = (ProfileViewController *)segue.destinationViewController;
           loadCtr.custid =self.tmpv1;
           loadCtr.mobilestrp = self.stri1;

       }
}

注意:确保segues的起点(启动segue)和结束点(您想要显示)是正确的。此外,总是在Storyborad上使用segue的唯一标识符。

答案 2 :(得分:1)

试试这个

解决方案1 ​​

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"ProfileViewController's identifier"])
    {
         ProfileViewController *loadCtr = (ProfileViewController *)segue.destinationViewController;
             loadCtr.custid =self.tmpv1;
             loadCtr.mobilestrp = self.stri1;
    }

    else if ([[segue identifier] isEqualToString:@"another identifier"])
    {

    }
}

解决方案2

检查两个viewcontroller分配的segue标识符,如果两者都相同,则分配不同的标识符。

答案 3 :(得分:-1)

检查profileViewController中的IBActions和变量是否有链接到您的文件。这是您的参考商店