【问题标题】:Swift: Storyboard TabViewController Segue Not Being TriggeredSwift:Storyboard TabViewController Segue 未被触发
【发布时间】:2015-07-28 03:41:37
【问题描述】:

我正在开发一个 iOS 应用程序,该应用程序允许用户将食品条码扫描到购物清单中。我的目标是,当扫描仪拾取条形码时,它会抓取元数据并将其(通过 segue)发送到另一个视图,用户可以在其中将项目记录到他们的购物清单中。我的错误是,当扫描仪拾取条形码并成功返回元数据时,它会调用performSegueWithIdentifier()(第 30 行),但实际上并没有进入下一个视图。它只会不断扫描条形码并输出我的打印语句,如下所示。父视图是一个带有三个选项卡的 TabBarViewController,其中一个是扫描仪。我正在使用RSBarcodes 框架,它可以在here 中找到。以下是说明我的错误的屏幕截图。

条码扫描器类

终端输出

故事板转场

模拟器视图

【问题讨论】:

    标签: ios swift uitabbarcontroller barcode-scanner rsbarcodes


    【解决方案1】:

    您应该在展示另一个视图控制器之前停止扫描。找到实现的方法来停止或释放框架中的扫描仪。

    【讨论】:

      【解决方案2】:

      就像Sachin Rocken 所说,您需要停止捕获会话以避免多次扫描。只需使用self.session.stopRunning() 即可捕获捕获会话。此外,在ScanItemViewController 内完成的任何 UI 操作都需要在主线程上完成。你的self.barcodesHandler 应该是模型:

      self.barcodesHandler = { barcodes in
          // print barcode found
          self.barcodeVal = barcodes[0].stringValue
          self.session.stopRunning() // Stops scanning processs to avoid multiple scans
          dispatch_async(dispatch_get_main_queue(), { () -> Void in
              self.performSegueWithIdentifier("presentAddItem", sender: self)
           }) // Any UI operation needs to be done on main thread            
      }
      

      【讨论】:

        猜你喜欢
        • 2013-04-30
        • 2012-02-15
        • 1970-01-01
        • 1970-01-01
        • 2013-01-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多