2017-06-05 206 views
1

嗨會話塊工作正常,但是當我想移動到下一個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刪除它,用右鍵單擊選項? –

回答

2

您沒有檢查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

-1

在profileViewController中檢查您的IBActions和變量是否有鏈接到您的文件。那是你的參考插座

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的分配賽格瑞標識符和如果兩者相同,則分配不同的標識符。

2

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的唯一標識符。