zoukankan      html  css  js  c++  java
  • 从其他文件包加载数据

    问题:

      在main bundle中可能还会有单独的bundle,这些单独的bundle中也会包含图片或者其它的一些资源,那么如何访问其中的资源呢? 

    方案:

      获取除了主文件包之外其他文件包内的文件时最好使用 NSBundle 中 pathForResource:ofType:inDirectory:的实例方法,特别是要直接获取那些制定文件包已经存在的文件和资源。 
     NSString *resourceBundlePath = [[NSBundle mainBundle]pathForResource:@"Resources" ofType:@"bundle"];
            if ([resourceBundlePath length] > 0) {
                NSBundle *resourceBundle = [NSBundle bundleWithPath:resourceBundlePath];
                if (resourceBundle != nil) {
                    NSString *pathToImage = [resourceBundle pathForResource:@"lixw_20140426_003" ofType:@"jpg" inDirectory:@"Images"];
                    if ([pathToImage length] > 0) {
                        NSLog(@"图片位置%@",pathToImage);
                    }else{
                        NSLog(@"没有找到");
                    }
                }else{
                    NSLog(@"加载bundle失败");
                }
            }else{
                NSLog(@"找不到指定的bundle");
            }
    如果你尝试查找文件包内特定文件夹里保存的所有资源,可以使用 NSBundle 类的实例 方法 pathsForResourcesOfType:inDirectory: 
    NSArray *paths = [resourcesBundle pathsForResourcesOfType:@"png"  inDirectory:@"images"];
    [paths enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop){
    NSLog(@"Path%lu = %@",(unsigned long)idx+1,obj);
    }];
  • 相关阅读:
    RSA算法
    随机数相关面试题
    黑冰
    Servlet
    中国文人的弱点
    黑客与画家
    J2SE、JS及JavaWeb的若干知识
    离婚前规则
    自己写的一个智能指针类
    用_makepath和_splitpath构造路径&分解路径
  • 原文地址:https://www.cnblogs.com/safiri/p/4011293.html
Copyright © 2011-2022 走看看