I recently started exploring JavaSciptCore in iOS 7.
Till now I have been able to use UILabel, UIButton and a few more of the UI elements using JSCore.
But now I am stuck while using the UITextField. For some reason, it does not appear on the screen but all the code is getting executed.
So my .h file has the following in a protocol which is implemented in the interface.
- (void)set:(JSValue *)config;
+ (id)create;
In my .m file I have the above functions defined.
+ (RZTextField *)create
{
RZTextField *textField = [[RZTextField alloc] init];
return textField;
}
-(void)set:(JSValue *)config
{
if (![config[@"text"] isUndefined]) {
self.text = [config[@"text"] toString];
}
if (![config[@"textColor"] isUndefined]) {
self.textColor = [Utils makeColor:[config[@"textColor"] toArray]];
}
if (![config[@"frame"] isUndefined]) {
self.frame = [Utils makeFrame:[config[@"frame"] toArray]];
self.keyboardType = UIKeyboardTypeDefault;
self.borderStyle = UITextBorderStyleRoundedRect;
}
if (![config[@"background"] isUndefined]) {
self.background = [Utils makeColor:[config[@"background"] toArray]];
}
}
And finally this is the JS code that gets executed:
//root view controller is created
App.rootVC = UI.ViewController.create();
App.rootVC.makeRootViewController();
App.rootVC.set({ background: [231, 76, 60, 1] });
App.textF = UI.TextField.create();
App.textF.set({
frame:[20, 500, 300, 120],
text: "some text",
textColor:[255, 255, 255, 1],
background:[255, 255, 255, 1]
});
App.rootVC.append(App.textF);
I did some debugging on my own so following are the points: - I have set breakpoints and checked. It goes to all the function calls. So everything is getting executed. - The root view controller works fine and I have been able to add other UI elements just fine. - The UITextField gets appended successfully. I know this because when I checked the parent of the text field, it returns the root view controller's address. - For some reason when I did initWithFrame:
from the create
function, then it showed a part of the text field as if the root view controller was partly of the visible screen! So whatever frame
I set, couldn't see more than half of the textfield!
Any ideas on what's going on?
I have some experience with CocoaScript
, the new name for JSTalk
which is a wrapper around JavaScriptCore
for OS X. It doesn't run on iOS but as far as I know could be ported, so perhaps you want to try porting it.
I'm not sure what CocoaScript does differently, or perhaps you are doing differently, but I have no trouble at all working with text fields in this bit of javascript: https://github.com/abhibeckert/Dux/blob/master/Default-Bundles/Lorem%20Ipsum.coscript
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.