我参考教程5+ App开发Native.js入门指南
按教程添加了.h和.m文件
在使用test()函数 回调时 xcode报错 EXC_BAD_ACCESS(code=1,address=0x8),求大大解答呀
ps:我测试不传参数时能成功调用回调函数
// 定义协议
@protocol NjsHelloEvent <NSObject>
@required
-(void) onEventInvoked:(NSString*)name;
@end
// -------------------------------------------------------------
// 定义类NjsHello
@interface NjsHello : NSObject {
NSString *_name;
id<NjsHelloEvent > _delegate;
}
@property (nonatomic,retain) NSString *name;
@property (nonatomic,retain) id delegate;
-(void)updateName:(NSString*)newname;
-(void)setEventObserver:(id<NjsHelloEvent >)delegate;
-(void)test;
+(void)testCount;
@end
#import "njshello.h"
// 实现类NjsHello
@implementation NjsHello
@synthesize name=_name;
-(void)updateName:(NSString*)newname{
_name = [newname copy];
}
-(void)setEventObserver:(id<NjsHelloEvent >)delegate{
_delegate = delegate;
}
-(void)test{
NSLog(@"My name is: %@",_name);
[[self delegate]onEventInvoked:_name];//!!!!!!!!!!!!!!!!!!!!!!!!! EXC_BAD_ACCESS(code=1,address=0x8)
}
-(void)dealloc{
[_name release];
[super dealloc];
}
+(void)testCount{
NSLog( @"Static test count" );
}
@end
// 导入测试类NjsHello
var NjsHello = plus.ios.importClass("NjsHello");
// 实现协议“NjsHelloEvent”的代理
var hevent = plus.ios.implements( "NjsHelloEvent", {
"onEventInvoked":function( name ){
console.log( "Invoked Object’s name: "+name ); // 输出“Invoked Object’s name: Tester”
}
} );
var hello = new NjsHello()
// 调用updateName方法
hello.updateName( "Tester" );
// 设置监听对象
hello.setEventObserver( hevent );
// 调用test方法,触发代理事件
hello.test(); // 触发上面代理对象定义的匿名函数运行
inu1255 (作者)
谢谢提醒,我去看看插件的文档,不过为什么回调时会报错呢?
2016-01-14 18:56
DCloud_IOS_XTY
报什么错?
2016-01-15 11:55
人员
在调用代理方法时,项目崩溃
2018-12-13 14:50