.h 文件
//定义协议
@protocol NjsAppMainEvent <NSObject>
@required
-(void) onEventInvoked:(NSString*)name;
@end
@interface NJSAppMain : NSObject{
NSString *_name;
id<NjsAppMainEvent > _delegate;
}
@property (nonatomic,retain) NSString *name;
@property (nonatomic,retain) id delegate;
-(void)setEventObserver:(id<NjsAppMainEvent >)delegate;
-(void)test;
@end
.m文件
import "NJSAppMain.h"
@implementation NJSAppMain
@synthesize name=_name,delegate=_delegate;
-(void)setEventObserver:(id<NjsAppMainEvent >)newDelegate{
NSLog(@"setEventObserver:%@",newDelegate);
_delegate = newDelegate;
}
-(void)test{
NSLog(@"setEventObserver:%@",[self delegate]);
[[self delegate] onEventInvoked:@"test"];
}
@end
.js文件
var appMainIOS = plus.ios.implements("NJSAppMain");
var appMainIOSDelete = plus.ios.implements("NjsAppMainEvent",{
"onEventInvoked":function(name){
alert("onEventInvoked:"+name);
}
});
appMainIOS.setEventObserver( appMainIOSDelete );
appMainIOS.test();
调用test方法的报错,是什么原因呢?
4 个回复
f***@126.com
是的,oc方法里传参数就错 不传参就可以。? 有哪位能解释下
f***@126.com
已解决
q***@163.com
能不能说下解决的方法
2017-05-04 23:54
hyfkobe
请问怎么解决的,急求啊
1***@qq.com
怎么解决的啊,急急急