如题,不知道该怎么写这个回调,试过delegate和Block都不行,感觉代码写的有问题,希望帮忙看下。代码如下
delegate:
var ScanViewController = plus.ios.importClass("ScanViewController");
var newVCobj = new ScanViewController();
var delegate = plus.ios.implements("ScanValueDelegate", {
"getScanValue":function(value){
alert(name);
}
});
newVCobj.setScanDelegate(delegate);
上面是H5页面的设置。我的ScanViewController中相关的代码截取
ScanViewController.h文件
@protocol ScanValueDelegate <NSObject>
@required
-(void) getScanValue:(NSString)value;
@end
typedef void (^CopyScanValue)(NSString value);
@interface ScanViewController : UIViewController {
id<ScanValueDelegate > _delegate;
}
@property (nonatomic,copy) CopyScanValue copyScanValue;
@property (nonatomic,retain) id<ScanValueDelegate> delegate;
-(void)setScanDelegate:(id<ScanValueDelegate>)delegate;
@end
ScanViewController.m文件中关键代码
回调方法
-(void)backAction {
[self dismissViewControllerAnimated:YES completion:^{
if(_delegate){
[_delegate getScanValue:@"hi"];
}
}];
}
设置代理
-(void)setScanDelegate:(id<ScanValueDelegate>)delegate{
_delegate = delegate;
}
而关于Block部分代码:
在H5中
var newVCobj = plus.ios.newObject("ScanViewController");
plus.ios.invoke( newVCobj, "setCopyScanValue:^", function(value){alert(value)} );
在原生中
-(void)backAction {
[self dismissViewControllerAnimated:YES completion:^{
if(self.copyScanValue){
self.copyScanValue(@"1");
}
}];
}
闻风 (作者)
感谢!
2016-02-17 09:29
q***@163.com
value值是空的啊
2017-05-04 22:23