-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
强制类型转换 #58
Comments
对OC返回的NSString/NSArray/NSDictionary调用
|
NSNumber回传到JS中是JS里的Number类型,转成字符串可以用JS中的toString()方法。 |
var num = self.dataSource().objectAtIndex(indexPath.row())
cell.textLabel().setText(num + "js") |
@albert438 没注意到它这里原来是number,其实不用 |
@bang590 👍 已改正。 var jsArray = self.dataSource().toJS()
cell.textLabel().setText(jsArray[indexPath.row()] + "JS") |
确实是中括号的问题 ,使用中括号后,取出来的值为 undefined。虽不报错,但是拿不到正确类型。js 语法与 OC 混用了。问题已经解决一下两种都可以: var jsArray = self.dataSource().toJS()
cell.textLabel().setText(jsArray[indexPath.row()] + "JS")
var num = self.dataSource().objectAtIndex(indexPath.row())
cell.textLabel().setText(num + "js") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
你好,我在JS中拿到OC 的 NSNumber 类型,在进行 NSNumber -->NSString的转换中,该怎么转换?
在 tableView_cellForRowAtIndexPath 方法中:
num 是一个在 OC 中的 NSNumber 对象。
var num = self.dataSource()[indexPath.row].sringValue();
cell.textLabel().setText(num +"js");
报错:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'js exception: TypeError: undefined is not an object (evaluating 'num.__c')'。
js的强制转换 String(value),不起作用。
The text was updated successfully, but these errors were encountered: