1

在模拟器中,我将从包中获取 obj 文件:

NSArray *myArray = [[NSBundle mainBundle] pathsForResourcesOfType:@"obj" inDirectory:nil];

在模拟器中,obj 文件按字母顺序打印:

/Users/name/Library/Application Support/iPhone Simulator/6.0/Applications/10FF2D60-7B33-4AE9-9CA2-95A951A55C49/3DModels.app/**banana.obj**,

/Users/name/Library/Application Support/iPhone Simulator/6.0/Applications/10FF2D60-7B33-4AE9-9CA2-95A951A55C49/3DModels.app/**plane3.obj**,

/Users/name/Library/Application Support/iPhone Simulator/6.0/Applications/10FF2D60-7B33-4AE9-9CA2-95A951A55C49/3DModels.app/**wolverine.obj**,

/Users/name/Library/Application Support/iPhone Simulator/6.0/Applications/10FF2D60-7B33-4AE9-9CA2-95A951A55C49/3DModels.app/**Wteapot.obj**,

/Users/name/Library/Application Support/iPhone Simulator/6.0/Applications/10FF2D60-7B33-4AE9-9CA2-95A951A55C49/3DModels.app/**XBODY.obj**,

/Users/name/Library/Application Support/iPhone Simulator/6.0/Applications/10FF2D60-7B33-4AE9-9CA2-95A951A55C49/3DModels.app/**YLID.obj**
)

但是ipad的obj文件不是按字母顺序打印的。

/Users/name/Library/Application Support/iPhone Simulator/6.0/Applications/10FF2D60-7B33-4AE9-9CA2-95A951A55C49/3DModels.app/**wolverine.obj,**

/Users/name/Library/Application Support/iPhone Simulator/6.0/Applications/10FF2D60-7B33-4AE9-9CA2-95A951A55C49/3DModels.app**/**Wteapot.obj**,**

/Users/name/Library/Application Support/iPhone Simulator/6.0/Applications/10FF2D60-7B33-4AE9-9CA2-95A951A55C49/3DModels.app/**plane3.obj**,

问题是什么?

4

2 回答 2

3

pathForResourcesOfType:inDirectory: 的 Apple 文档说:

包含与指定条件匹配的所有捆绑资源的完整路径名的数组。如果没有找到匹配的资源文件,则此方法返回一个空数组。

这意味着 Apple 并没有说它会以任何特定的顺序为您提供路径,但如果您需要它以某种顺序,您可以自己排序。

NSArray *sorted = [myArray sortedArrayUsingComparator:^NSComparisonResult(NSString *str1, NSString *str2) 
{
    return [s1 localizedCaseInsensitiveCompare:s2];
}];

所以现在你已经对所有路径的 NSArray 进行了排序。

于 2013-09-24T13:14:01.627 回答
1

我认为您的某些 obj 文件名起始字符是大写字母。只需更改那些文件名的起始字符是小写字母。

于 2013-09-25T06:53:08.493 回答