繁体   English   中英

NSInvalidArgumentException与stringByAppendingPathComponent

[英]NSInvalidArgumentException with stringByAppendingPathComponent

我有一个带有字符串的Bundel设置:版本

在我的捆绑软件设置版本中= 2.9.1

在我的项目中,如果我使用此代码,一切都很好:

NSString *path = [documentsDirectory stringByAppendingPathComponent:@"ma/V_2.9.1/gma2/fixture_layers/ifocus.xml"];

如果我使用此代码:

NSString *path = [documentsDirectory stringByAppendingPathComponent:(@"ma/V_%@/gma2/fixture_layers/ifocus.xml", version)];

我有这个错误:

*由于未捕获的异常“ NSInvalidArgumentException”而终止应用程序,原因:“-[UITextField长度]:无法识别的选择器已发送到实例0x9753190”

NSString * path = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@“ ma/V_%@/gma2/fixture_layers/ifocus.xml”,版本]];

由于您已经在字符串中包含多个/,因此使用stringByAppendingPathComponent没有优势。 因此,您最好只使用:

NSString* path = [documentsDirectory stringByAppendingFormat:@"ma/V_%@/gma2/fixture_layers/ifocus.xml", version];

给您带来stringByAppendingPathComponent好处的另一种选择是像这样将其分解:

NSString* path = [[[[[documentsDirectory stringByAppendingPathComponent:@"ma"] stringByAppendingPathComponent:[NSString stringWithFormat:@"V_%@", version]] stringByAppendingPathComponent:@"gma2"] stringByAppendingPathComponent:@"fixture_layers"] stringByAppendingPathComponent:@"ifocus.xml"];

但这有点丑陋。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM