zoukankan      html  css  js  c++  java
  • 在 ZBarSDK 中使用Block回调传值 Block在扫描成功后 变为空

    今天,使用ZbarSDk 实现二维码扫描的功能,使用block回调传递扫描成功的获取的值   但是在扫码成功后block 就变为空了.....心塞塞的

     代码如下  主页面跳转到扫码界面

        //跳转到扫码界面

        ReadCodeViewController * readVC = [[ReadCodeViewController alloc]init];

        readVC.scanCodeResult = ^(NSString *result)

        {

            [self addPcdMerch:result];

        };

           [self presentViewController:readVC animated:YES completion:nil];

    扫码成功后  代码如下

    -( void )readerView:( ZBarReaderView *)readerView didReadSymbols:( ZBarSymbolSet *)symbols fromImage:( UIImage *)image

     

    {

        [timer invalidate];

        [self.zBarReadView stop];

        _line.frame = CGRectMake(30, 10, 220, 2);

        

        const zbar_symbol_t *symbol = zbar_symbol_set_first_symbol (symbols. zbarSymbolSet );

        

        NSString *symbolStr = [ NSString stringWithUTF8String : zbar_symbol_get_data (symbol)];

     

        if(self.scanCodeResult)

        {

            self.scanCodeResult(symbolStr);

        }

     

        [self dismissViewControllerAnimated:YES completion:nil];

    }

    最后,发现问题出在对Block 进行申明的时候 

    @property (nonatomic, assign) ScanCodeResultBlock scanCodeResult;

    使用了assign,将其改为strong后就OK.  

    那么我们简单说下assign  strong/weak copy 的使用吧

    assign  基本数据类型

    strong/weak 各种控件

    copy   只用来赋值用的 如 NSString  

    最后,将在Block 申明时使用了copy

     

     

  • 相关阅读:
    C#调用Halcon
    C#跨窗体程序调用方法的具体操作
    C#调用DLL报错:试图加载格式不正确的程序
    C#窗体程序设置禁用关闭按钮
    C#窗体程序设置禁用关闭按钮
    C#在字符串中查询指定字符串是否存在
    poj1654
    poj1873
    poj2451
    poj1113
  • 原文地址:https://www.cnblogs.com/designyshy/p/4913763.html
Copyright © 2011-2022 走看看