Objective-C 上的 setTimeout("function (" "+ argument "#x2B;")", value)
我如何在 Objective-C 上编码 javascript 行:
setTimeout("function("+argument+")", value);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
其实不是很清楚自己想要什么。我想你想以 Objective C 的方式做到这一点。因此,您需要使用 NSTimer:
编辑:但是,如果您只想将其用作字符串,请按照丹尼尔所示进行编写。
It is actually not very clear what do you want. I suppose that you want to do that in Objective C way. So you need to use NSTimer:
Edit: however if you just want to use that as string then write as Daniel has shown.
首先,尽管您可以在“setTimeout”中使用字符串计算,但它的成本昂贵且可读性差得多。
最好使用参考。请阅读 http://yuiblog.com/blog /2006/11/13/javascript-we-hardly-new-ya/。
让我们按如下方式重写您的 Javascript:
上面的结构可以很好地转换为 NSTimer 类函数。
首先定义你的函数:
并在延迟一段时间后调用你的函数......
就这样。延迟 1 秒后异步函数调用。
您可能会问参数在哪里?好吧,这是一个需要 NSInitation 对象的额外步骤,在 @selector 中的参数 中
对此 进行了很好的解释问题“我如何在 Objective-C 上编码 javascript 行:”的方式尚不清楚,我相信您需要一个类似于 setTimeout 方法 Javascript 但在 Objective-C 中的示例
Firstly with javascript although you can use a string evaluation in "setTimeout", it's expensive and far less readable.
It is far better to use a reference instead. Please read http://yuiblog.com/blog/2006/11/13/javascript-we-hardly-new-ya/.
Lets re-write your Javascript as follows:
The above structure translates into the NSTimer class function quite well.
First define your function:
And to call your function after some delay...
And there you have it. An Asynchronous function call after a delay of 1 second.
Where are the parameters you may ask? Well it is a little extra step requireing a NSInvocation object which is explained quite nicely at Arguments in @selector
By the way the question "How can I encode on objective-C the line of javascript:" is not clear, i believe you requiring an example similar to the setTimeout method Javascript but in Objective-C