无法执行segue

问题描述:

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

- (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  

在此先感谢您的建议!

+0

'uodateb' outlet连接到某个UI元素,但未在ViewController文件中声明。有很多关于此的SO帖子,你应该已经检查过“这个类别不是关键值编码 - 关键字”搜索项 –

+0

我没有像这样的UI元素,我已经删除了该元素@ Mr .Bista和是的,我已经经历了老问题,我抱怨得到任何答案,所以我发布了一个新的 – Akshay

+0

你有没有从xib删除它,用右键单击选项? –

您没有检查segue标识符 in prepareForSegue方法。

检查它像这样:

-(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 
    } 
} 

有了这个,你可以有特定的视图控制器和它的属性来设置。

+0

是我的if语句正确吗???因为它不会执行两个segges @DashAndRest – Akshay

+0

您可以使用'isEqualToString'方法来检查字符串是否相等,最好是用断点调试代码并检查是否有任何'x2'或'b2'正在执行 – D4ttatraya

+0

是的,我做了这个使用断点它绝对读取从开始的所有代码(!错误)直到结束,突然它执行b2有时再给thread1错误 – Akshay

在profileViewController中检查您的IBActions和变量是否有链接到您的文件。那是你的参考插座

尝试此

溶液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定义了两个视图控制器之间的转换。虽然在你的情况下,赛格呈现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; 

     } 
} 

注:确保起点(启动SEGUE)和终点(要显示)塞格斯是正确的。而且总是在你的Storyborad上使用segue的唯一标识符。