You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed that defineClass (JPEngine.m:144) only override those methods that already exsit in the OC class; otherwise the new methods of user define stay in JS, which mean you can't call your new methods in OC.
So you can't use the target actions pattern and selector, and I guess is really important:
varbutton=UIButton.alloc().init()// It doesn't work, and you can't create selector like that for now.button.addTarget_action_forControlEvents(self, @selector("buttonTapped:",0)
In the demo, it doesn't work when handleBtn doesn't exist:
// JPViewController@implementationJPViewController
- (void)viewDidLoad {
[superviewDidLoad];
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 100, [UIScreen mainScreen].bounds.size.width, 50)];
[btn setTitle:@"Push JPTableViewController"forState:UIControlStateNormal];
// try to call @selector(handleBtn:), which define in demo.js
[btn addTarget:selfaction:@selector(handleBtn:) forControlEvents:UIControlEventTouchUpInside];
[btn setBackgroundColor:[UIColor grayColor]];
[self.view addSubview:btn];
}
/** comment this and it will crash- (void)handleBtn:(id)sender{}*/@end
I guess we can covert all the user define JS functions into OC methods(override if exist, add new one if not) to solve this problem, and define a new way to convert string(or something else) to SEL from JS to OC.
Any suggestion?
The text was updated successfully, but these errors were encountered:
@lancy the problem is if we want to add method to an OC class dynamically, we should know the type of all params and return value, but the JS function didn't mention these types. I'm figuring out a way to pass types from JS to OC, would be updated soon.
Hey
I noticed that
defineClass
(JPEngine.m:144) only override those methods that already exsit in the OC class; otherwise the new methods of user define stay in JS, which mean you can't call your new methods in OC.So you can't use the target actions pattern and selector, and I guess is really important:
In the demo, it doesn't work when handleBtn doesn't exist:
I guess we can covert all the user define JS functions into OC methods(override if exist, add new one if not) to solve this problem, and define a new way to convert string(or something else) to SEL from JS to OC.
Any suggestion?
The text was updated successfully, but these errors were encountered: