【问题标题】:Why does it say I have two arguments?为什么它说我有两个论点?
【发布时间】:2013-12-24 19:46:17
【问题描述】:

它说我有两个参数,我不是只有一个吗?[_webView stringByEvaluatingJavaScriptFromString:@"document.getElementById('select').selectedIndex = %@", selection];

【问题讨论】:

    标签: javascript objective-c xcode uiwebview


    【解决方案1】:

    仔细查看代码行,尤其是“,”后面的“选择”。这不是有效的 Objective-C。

    方法是:

    - (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script
    

    重构:我想你的意思是(FWIW 我不懂 JavaScript):

    NSString *javaScript = [NSString stringWithFormat:@"document.getElementById('select').selectedIndex = %@", selection];
    [_webView stringByEvaluatingJavaScriptFromString: javaScript];
    

    将复合语句分解成单独的语句确实有助于发现错误。

    【讨论】:

      猜你喜欢
      • 2022-10-17
      • 1970-01-01
      • 1970-01-01
      • 2014-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-10
      相关资源
      最近更新 更多