2016-08-27 11 views
0

私のコードに問題があります。self.navigationController.pushViewController機能が無限と呼ばれています。コードが添付されています。バーコードを読み取って製品情報を取得しています。ナビゲーションコントローラshow/push viewcontroller swift

詳細:詳細: 詳細: 詳細:詳細:

func captureOutput(captureOutput: AVCaptureOutput!, didOutputMetadataObjects metadataObjects: [AnyObject]!, fromConnection connection: AVCaptureConnection!) { 

    let storyboard = UIStoryboard(name: "Main", bundle: nil) 
    let nav = storyboard.instantiateViewControllerWithIdentifier("companyInfoNAv") as! UINavigationController 
    let companyInfoView = nav.topViewController as! CompanyInformationViewController //  toggleFlash() 
    for meta_Data in metadataObjects { 

     let decoded_data: AVMetadataMachineReadableCodeObject = meta_Data as! AVMetadataMachineReadableCodeObject 

     self.output_Label.text = decoded_data.stringValue 
     self.reader_Type.text = decoded_data.type 



     let manager: AFHTTPSessionManager = AFHTTPSessionManager.init() 
     manager.GET("https://api.outpan.com/v2/products/"+decoded_data.stringValue+"?apikey="+"944b2810f5072d9d125f5fcf32543r1", parameters: nil, success: { (NSURLSessionDataTask, responseObject) in 

      self.arrayObjects = responseObject as! NSDictionary 

      print(self.arrayObjects) 


      if((self.arrayObjects.objectForKey("name")?.empty) == nil){ 
       let attributes : NSDictionary! 

       attributes = self.arrayObjects.objectForKey("attributes") as! NSDictionary 
       if(attributes.count > 3){ 
        if(attributes.objectForKey("Manufacturer")?.empty == nil){ 
         companyInfoView.companyName = attributes.objectForKey("Manufacturer") as! NSString as String 


        } 
       }else{ 

        companyInfoView.companyName = "No Name in DATABASE" 


       } 
      } 
      else{ 
       companyInfoView.companyName = "No Name in DATABASE" 

      } 


      print(self.arrayObjects.objectForKey("name")) 
      }, failure: { (operation, error) in 
       print(error) 
     }) 





    } 
    self.navigationController?.pushViewController(companyInfoView, animated: true) 

} 
+0

あなたのストーリーボードで、あなたのscannerPageとcompanyInfoViewをリンクしましたか? – Carlo

答えて

0

あなたのAPIマネージャを使用すると、以下のようにsuccessブロック内navigation controllerをプッシュする必要があり、非同期的に実行、または完了を使用しています

manager.GET("https://api.outpan.com/v2/products/"+decoded_data.stringValue+"?apikey="+"944b2810f5072d9d125f5fc1217855f1", parameters: nil, success: { (NSURLSessionDataTask, responseObject) in 

     self.arrayObjects = responseObject as! NSDictionary 

     print(self.arrayObjects) 


     if((self.arrayObjects.objectForKey("name")?.empty) == nil){ 
      let attributes : NSDictionary! 

      attributes = self.arrayObjects.objectForKey("attributes") as! NSDictionary 
      if(attributes.count > 3){ 
       if(attributes.objectForKey("Manufacturer")?.empty == nil){ 
        companyInfoView.companyName = attributes.objectForKey("Manufacturer") as! NSString as String 


       } 
      }else{ 

       companyInfoView.companyName = "No Name in DATABASE" 


      } 
     } 
     else{ 
      companyInfoView.companyName = "No Name in DATABASE" 

     } 


     print(self.arrayObjects.objectForKey("name")) 
     // push the navigation controller here 
     self.navigationController?.pushViewController(companyInfoView, animated: true) 

     }, failure: { (operation, error) in 
      print(error) 
    }) 
関連する問題