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);
    }];
  • 相关阅读:
    【学习】018 Spring框架
    【学习】017 Mybatis框架
    【学习】016 MySQL数据库优化
    【学习】 015 Linux相关
    【学习】014 深入理解Http协议
    【学习】013 Servlet、Cookie、Session的简述
    js 异常判断
    CSS 文字概念小记
    Echarts tooltip 坐标值修改
    js 查找当前元素/this
  • 原文地址:https://www.cnblogs.com/safiri/p/4011293.html
Copyright © 2011-2022 走看看