【问题标题】:Navigation Controller show/push viewcontroller swift导航控制器显示/推送视图控制器 swift
【发布时间】:2016-08-27 14:29:28
【问题描述】:

我的代码有问题,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)

}

【问题讨论】:

  • 您已将您的扫描仪页面与情节提要中的 companyInfoView 链接?

标签: ios swift navigation views barcode


【解决方案1】:

您的 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)
    })

【讨论】:

    猜你喜欢
    • 2012-01-23
    • 2014-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多