我的代码中有一个问题self.navigationController.pushViewController
函数被称为无限时间,我的代码被附加,我通过读取条形码获取产品信息。
更多详情:更多详情: 更多细节: 更多细节:更多细节:
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 :(得分:0)
您的API管理器是异步执行的,您应该按下navigation controller
块中的success
,如下所示,或使用完成
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)
})