- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我如何全局定义(条形码扫描)以便我的所有功能都可以访问它。换句话说,我如何全局定义“metadataObj”?
class ScanController: UIViewController, AVCaptureMetadataOutputObjectsDelegate {
var captureSession: AVCaptureSession?
var videoPreviewLayer: AVCaptureVideoPreviewLayer?
var qrCodeFrameView: UIView?
override func viewDidLoad() {
super.viewDidLoad()
//Get an instance of the AVCaptureDevice class a device object and provide the video as the media type parameter
let captureDevice = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo)
do {
// Get an instance of the AVCaptureDeviceInput class using the previous device object.
let input = try AVCaptureDeviceInput(device: captureDevice)
// Initialize the captureSession object.
captureSession = AVCaptureSession()
// Set the input device on the capture session.
captureSession?.addInput(input)
let captureMetadataOutput = AVCaptureMetadataOutput()
captureSession?.addOutput(captureMetadataOutput)
// Set delegate and use the default dispatch queue to execute the call back
captureMetadataOutput.setMetadataObjectsDelegate(self, queue: DispatchQueue.main)
captureMetadataOutput.metadataObjectTypes = supportedCodeTypes
// Initialize the video preview layer and add it as a sublayer to the viewPreview view's layer.
videoPreviewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
videoPreviewLayer?.videoGravity = AVLayerVideoGravityResizeAspectFill
videoPreviewLayer?.frame = view.layer.bounds
view.layer.addSublayer(videoPreviewLayer!)
// Start video capture.
captureSession?.startRunning()
//initialize QR Code Frame to highlight the QR Code
qrCodeFrameView = UIView()
if let qrCodeFrameView = qrCodeFrameView {
qrCodeFrameView.layer.borderColor = UIColor.green.cgColor
qrCodeFrameView.layer.borderWidth = 2
view.addSubview(qrCodeFrameView)
}
} catch {
// If any error occurs, simply print it out and don't continue any more.
print(error)
return
}
}
func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputMetadataObjects metadataObjects: [Any]!, from connection: AVCaptureConnection!) {
// Check if the metadataObjects array is not nil and it contains at least one object.
if metadataObjects == nil || metadataObjects.count == 0 {
qrCodeFrameView?.frame = CGRect.zero
messageLabel.text = "No QR/barcode is detected"
return
}
//Get metadata object
let metadataObj = metadataObjects[0] as! AVMetadataMachineReadableCodeObject
if supportedCodeTypes.contains(metadataObj.type) {
//if the found metadata is equal to the QR code metadata then update the status label's text and set the the bounds
let barCodeObject = videoPreviewLayer?.transformedMetadataObject(for: metadataObj)
qrCodeFrameView?.frame = barCodeObject!.bounds
if metadataObj.stringValue != nil {
messageLabel.text = metadataObj.stringValue
//Searches firebase for existing barcode
}
let itemToSearchFor = metadataObj.stringValue
let itemID = metadataObj.stringValue
guard let Description = productDescriptionTextField.text,
let price = priceTextField.text,
let location = productLocationTextField.text
else{
print("Fill basic product information")
return
}
let ref = FIRDatabase.database().reference(fromURL: " /")
// creating an item child node
let values = ["Item Description": Description, "Image": price, "Location": location, "Price": price ]
let items = ref.child("Items").child(itemID!)
items.updateChildValues(values, withCompletionBlock: { (err, ref) in
if err != nil {
print(err)
return
} })
FIRDatabase.database().reference().child("Items").child(itemToSearchFor!).observeSingleEvent(of: .value, with:{(snap) in
print(snap)
})
self.setupNewProductEntry()
self.setupenterNewProductButton()
}
}
当我尝试在另一个函数中使用 ItemID 时出现一个错误。我认为这是因为它不是全局定义的,它只在 func captureOutput 内部定义。关于如何全局定义我从条码扫描仪获得的条码字符串值有什么想法吗?
最佳答案
你可以将它移到你的类范围之外,这样它就会变得全局并且在你的所有模块中可见
关于ios - 未解析的标识符 "itemID",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40633201/
我希望通过在变量名称前使用冒号来在路由中包含参数 // dynamic pages for each ITEM, once selected // from $routeParams.itemID i
第一篇文章在这里;) 我需要一些帮助,我正在开发一个约会加载项,但我无法获取当前项目的 itemID。我正在使用 mac os outllok dekstop 客户端(最新版本),我尝试使用: var
我是 Sitecore 新手,对此有一个基本问题。当我创建 Sitecore 项目时,会为此项目创建唯一 ID。如果我在代码中使用此项目 ID 来保存对其的引用,可以吗?从部署到部署这会发生变化吗?
我正在阅读该文档,它指出以 的形式设置别名 'widget.xxx.yyy' 然后 xtype 将自动设置为 'xxx.yyy' 我遇到的问题是我设置了别名和 itemId。看来 item
我如何全局定义(条形码扫描)以便我的所有功能都可以访问它。换句话说,我如何全局定义“metadataObj”? class ScanController: UIViewController, AVCa
我有一个通过 XML 资源定义的菜单。现在我动态地添加一个菜单项 public boolean onCreateOptionsMenu(Menu menu) { MenuInflater in
好的,所以当有人从我的网站购买商品时,需要将该商品 ID 插入数据库,但由于某种原因没有插入。 $mysql_host = 'localhost'; //Leave at localhost $my
在类定义(而不是实例化)上配置 itemId 是一种不好的做法吗? 是否有一些官方文档支持它,或者它只是一个意见问题? 或者,也许我缺少一些逻辑,可以清楚地表明这是一种不好的做法。 Ext.defin
我有一个如下所示的数据框: userid itemid score 1 5 4 2 3 10 1 5 20 2
我拥有一个 DDD/CQRS 应用程序。 我的问题涉及通过 POST(Rest)处理项目创建。 CQRS(基于CQS原则)提倡命令不应该返回值。 那里有查询。 所以我想知道如何处理项目创建的用例。 这
EWS 文档表示,要发送消息并将副本保存到“已发送邮件”文件夹,您应该 use the CreateItem operation with a MessageDisposition value of
我有一个自定义的 sitecore 按钮,它可以更改当前项目的模板,非常简单。 但是,作为其中的一部分,我还尝试将旧布局的渲染迁移到新布局,如果它属于 ItemId 的某个子布局类型| .然而Item
public class ListsSQLiteOpenHelper extends SQLiteOpenHelper { public static final int VERSION = 1; p
我想得到 ItemID From any product url on Amazon for ex. : http://www.amazon.com/gp/product/B0140RDK8W/ref
我在基于 Sencha Touch 2 的应用程序中工作,我有不同的按钮,可能会有不同的徽章文本。我当前在 View 中的代码是: items: [ {
示例 HTML: 示例 CSS: #MenuContainer { /* Styles */ } 如何使用 CSS 来定位 ItemID 而不是常规的 ID? 最佳答案 使用这个代替#Menu
我正在尝试查询vidispine用于一组项目的作业。问题是itemId保存在作业的元数据中。 Filtering over job's metadata是可能的,但我找不到有关一些更高级的过滤器标准及
我目前有一个 Excel 文件,其中一列用于 ItemID,一列用于 ItemName,采用这种样式: ItemID, ItemName 2, Apple 4, Orange 5, Pear 6, B
我有一个这样的窗口类: Ext.define('EMS.tf.alerts.alerts.view.AlertWindow', { extend: 'Ext.window.Window',
我正在尝试摆弄 SenchaCmd 6 在执行 sencha 应用程序生成 时生成的库存应用程序,并且我在侧面菜单选项卡上添加点击事件,如下所示: Ext.define('UserManager.vi
我是一名优秀的程序员,十分优秀!