Ios 带有stringByAppendingPathComponent的NSInvalidArgumentException

Ios 带有stringByAppendingPathComponent的NSInvalidArgumentException,ios,Ios,我有一个带字符串的bundel设置:version 在我的捆绑包设置中,版本=2.9.1 在我的项目中,如果我使用此代码,一切都很好: NSString *path = [documentsDirectory stringByAppendingPathComponent:@"ma/V_2.9.1/gma2/fixture_layers/ifocus.xml"]; 如果我使用此代码: NSString *path = [documentsDirectory stringByAppendingPa

我有一个带字符串的bundel设置:version

在我的捆绑包设置中,版本=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 length]:未识别的选择器已发送到实例0x9753190”

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


因为您已经在字符串中包含多个/,所以使用stringByAppendingPathComponent没有任何好处。因此,您不妨使用:

NSString* path = [documentsDirectory stringByAppendingFormat:@"ma/V_%@/gma2/fixture_layers/ifocus.xml", version];
另一个选项是将stringByAppendingPathComponent分解如下,它为您提供了stringByAppendingPathComponent的好处:

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

但这有点难看。

试试
NSString*path=[DocumentsDirectoryStringByAppendingPathComponent:[nsstringStringWithFormat:@“ma/V_%@/gma2/fixture_layers/ifocus.xml”,version]我尝试此NSString*路径=[DocumentsDirectoryStringByAppendingPathComponent:[NSString stringWithFormat:@“ma/V_U%@/gma2/fixture_layers/ifocus.xml”,版本]];NSLog(@“aaaaaaa%@”,路径);我有这个错误:aaaaaaa/var/mobile/Applications/2D2290A0-6C9B-4260-BBD7-560CCF29A0E6/Documents/ma/V_/gma2/fixture_layers/ifocus.xmli使用NSString*path=[Documents目录stringByAppendingFormat:@“ma/V_%@/gma2/fixture_layers/ifocus.xml”,version];NSLog(@“aaaaaaa%@”,路径);我有这个错误:aaaaaaa/var/mobile/Applications/2D2290A0-6C9B-4260-BBD7-560CCF29A0E6/Documentsma/V_2;/gma2/fixture_layers/ifocus.xml看起来您的
version
变量是
UITextField
,而不是带有版本号的
NSString
。因此,请改用
version.text