2017-06-29 4 views
0

私は特定の条件に応じて条件のセグを実装しようとしていましたが、どこに遅れているのか分かりません。誰でも助けてくれると助かります コード: - 処理する必要があり2 segues、segueOtp & segueError条件付きセグの使い方

@IBAction func btnToOtpScreen(_ sender: Any) { 

     let providedMarketingRef = txtMarketingRef.text 
     //let providedhopName = txtShopName.text 

     if((providedMarketingRef?.isEmpty)!) 
     { 
      displayAlertMessage(messageToDisplay: "Enter Your Marketing Reference") 

     } 

     else 
     { 

      let myUrl = URL(string: "http://kumbhkaran.co.in/ios_otp_check/request_sms.php"); 

      //let myUrl = URL(string: "http://kumbhkaran.co.in/OTPCheck/request_sms.php"); 
      var request = URLRequest(url:myUrl!); 
      request.httpMethod = "POST"; 

      let postString = "email=\(Email)&mobile=\(UserName)&name=\(ShopName)" 

      request.httpBody = postString.data(using: String.Encoding.utf8); 

      let task = URLSession.shared.dataTask(with: request) { (data: Data?, response: URLResponse?, error: Error?) in 

       DispatchQueue.main.async 
        { 

         //spinningActivity!.hide(true) 

         if error != nil { 
          self.displayAlertMessage(messageToDisplay: error!.localizedDescription) 
          return 
         } 

         do { 
          let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as? NSDictionary 

          if let parseJSON = json { 

           var msg : String! 

           //getting json response 
           msg = parseJSON["message"] as! String? 

           print(msg) 

         if(msg == "SMS request is initiated! You will be receiving it shortly.") 
          { 

          //self.performSegue(withIdentifier: "segueOTP", sender: self) 

          self.GlobalSegue="segueOTP" 
          } 
          else if(msg == "Sorry! Error occurred in registration.") 
          { 
           //self.performSegue(withIdentifier: "segueError", sender: self) 
          self.GlobalSegue="segueError" 
          } 

          else if(msg == "Mobile number already existed!") 
          { 
          //self.performSegue(withIdentifier: "segueError", sender: self) 
          self.GlobalSegue="segueError" 
          } 
          else if(msg == "Sorry! mobile number is not valid or missing.") 
          { 
           //self.performSegue(withIdentifier: "segueError", sender: self) 
           self.GlobalSegue="segueError" 
          } 


          } 
         } catch{ 
          print(error) 
         } 



       } 

      } 

      task.resume() 


     } 

    } 

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 

    if (GlobalSegue=="segueOTP") 
    { 
    let destViewController : OTPScreen = segue.destination as! OTPScreen 
    destViewController.Category = Category 
    destViewController.SubCategory = SubCategory 
    destViewController.ShopName = ShopName 
    destViewController.ManagerName = ManagerName 
    destViewController.ManagerMobile = ManagerMobile 
    destViewController.UserName = UserName 
    destViewController.Landline = Landline 
    destViewController.Email = Email 
    destViewController.Website = Website 
    destViewController.City = City 
    destViewController.Address = Address 
    destViewController.Area = Area 
    destViewController.Pincode = Pincode 
    destViewController.StartTime = StartTime 
    destViewController.EndTime = EndTime 
    destViewController.ShopStatus = ShopStatus 
    destViewController.HomeDelivery = HomeConsultancy 
    destViewController.Password = Password 
    destViewController.MarketingRef = txtMarketingRef.text! 
    destViewController.ImgShopName = ShopName 
    destViewController.OtherCategory = Other 
    destViewController.WorkerCount = WorkerCount 
    destViewController.latitude = lblLatitude.text! 
    destViewController.longitude = lblLongitude.text! 
} 
    else 
    { 
     var _ : ErrorController = segue.destination as! ErrorController 
    } 

} // のErrorControllerとおめでとうがありますが、私は条件に基づいて転用したい2つの異なるビューがあります。

+1

あなたの問題は何ですか?何が起こるのですか?あなたは何をしたいですか? – Paulw11

+0

if else条件をチェックすると、それらのsegueは機能しません。異なる条件で2つの異なるセグを呼び出す必要があります。 – himesh

+0

ブレークポイントを設定し、コードをステップ実行します。大丈夫だと思われますが、あなたの条件が満たされていない可能性があります。 – Paulw11

答えて

0

あなたはその識別子によりseguesを区別する必要があります。

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 

    switch segue.identifier { 

    case "segueOTP": 
     let destViewController = segue.destination as! OTPScreen 
     destViewController.Category = Category 
     destViewController.SubCategory = SubCategory 
     destViewController.ShopName = ShopName 
     destViewController.ManagerName = ManagerName 
     destViewController.ManagerMobile = ManagerMobile 
     destViewController.UserName = UserName 
     destViewController.Landline = Landline 
     destViewController.Email = Email 
     destViewController.Website = Website 
     destViewController.City = City 
     destViewController.Address = Address 
     destViewController.Area = Area 
     destViewController.Pincode = Pincode 
     destViewController.StartTime = StartTime 
     destViewController.EndTime = EndTime 
     destViewController.ShopStatus = ShopStatus 
     destViewController.HomeDelivery = HomeConsultancy 
     destViewController.Password = Password 
     destViewController.MarketingRef = txtMarketingRef.text! 
     destViewController.ImgShopName = ShopName 
     destViewController.OtherCategory = Other 
     destViewController.WorkerCount = WorkerCount 
     destViewController.latitude = lblLatitude.text! 
     destViewController.longitude = lblLongitude.text! 

    case "segueError": 
     var _ = segue.destination as! ErrorController 

    default : break 

    } 
} 

注:

を変数名は小文字で開始することを命名規則に準拠してください。