Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 如何在目标C中设置转义序列?_Objective C_Cocoa Touch_Nsstring - Fatal编程技术网

Objective c 如何在目标C中设置转义序列?

Objective c 如何在目标C中设置转义序列?,objective-c,cocoa-touch,nsstring,Objective C,Cocoa Touch,Nsstring,我有一个小代码: NSString *size = [LabelNewContent stringByEvaluatingJavaScriptFromString:@"return Math.max( document.body.scrollHeight, document.documentElement.scrollHeight, document.body.offsetHeight, document.documentElement.offsetHeight, document.bo

我有一个小代码:

NSString *size = [LabelNewContent stringByEvaluatingJavaScriptFromString:@"return     Math.max(
document.body.scrollHeight, document.documentElement.scrollHeight,
document.body.offsetHeight, document.documentElement.offsetHeight,
document.body.clientHeight, document.documentElement.clientHeight
);"];

问题是xcode无法将括号和逗号作为一个完整的字符串来识别。

使用
\
将其设置为多行字符串

NSString *size = [LabelNewContent stringByEvaluatingJavaScriptFromString:@"return     Math.max(\
document.body.scrollHeight, document.documentElement.scrollHeight,\
document.body.offsetHeight, document.documentElement.offsetHeight,\
document.body.clientHeight, document.documentElement.clientHeight\
);"];

使用
\
使其成为多行字符串

NSString *size = [LabelNewContent stringByEvaluatingJavaScriptFromString:@"return     Math.max(\
document.body.scrollHeight, document.documentElement.scrollHeight,\
document.body.offsetHeight, document.documentElement.offsetHeight,\
document.body.clientHeight, document.documentElement.clientHeight\
);"];
试试上面的事


尝试上述操作

将代码替换为

NSString *size = [LabelNewContent stringByEvaluatingJavaScriptFromString:@"return %f",Math.max(
                      document.body.scrollHeight, document.documentElement.scrollHeight,
                      document.body.offsetHeight, document.documentElement.offsetHeight,
                      document.body.clientHeight, document.documentElement.clientHeight
                      )];

希望它能帮助您。

将您的代码替换为

NSString *size = [LabelNewContent stringByEvaluatingJavaScriptFromString:@"return %f",Math.max(
                      document.body.scrollHeight, document.documentElement.scrollHeight,
                      document.body.offsetHeight, document.documentElement.offsetHeight,
                      document.body.clientHeight, document.documentElement.clientHeight
                      )];

希望它能对您有所帮助。

原因:如果不转义回车符,就无法将字符串文字包装到多行上。原因:如果不转义回车符,就无法将字符串文字包装到多行上。这是不正确的
Math.max()
document.body.etc
document.documentElement.etc
都是JavaScript,因此应该在字符串中。是正确的。这是错误的
Math.max()
document.body.etc
document.documentElement.etc
都是JavaScript,因此应该在字符串中。是正确的。