在模拟器中,我将从bundle获取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**,
有什么问题?
答案 0 :(得分:3)
Apple Document of pathsForResourcesOfType:inDirectory:说:
包含所有捆绑资源的完整路径名的数组 匹配指定的标准。此方法返回一个空数组if 找不到匹配的资源文件。
这意味着Apple并没有说它会以任何特定的顺序为您提供路径,但如果您需要它的顺序比您自己排序的那样。
NSArray *sorted = [myArray sortedArrayUsingComparator:^NSComparisonResult(NSString *str1, NSString *str2)
{
return [s1 localizedCaseInsensitiveCompare:s2];
}];
所以现在你已经对所有路径的NSArray进行了排序。
答案 1 :(得分:1)
我认为你的一些obj文件名起始字符是大写字母。只需更改那些起始字符的文件名是小写字母。