懒加载、plist文件数据加载、图片显示

来源:互联网 发布:电脑做账软件 编辑:程序博客网 时间:2024/05/22 15:34

懒加载、plist文件数据加载

  • plist文件数据的加载:

    • 先获取工程目录下的资源。

      获取工程目录

      NSBundle *bundle = [NSBundle mainBundle];  

      通过资源文件名和类型获取指定的资源文件路径

      NSString *path = [bundle pathForResource:@"imageData" ofType:@"plist"];  

      获取plist中数据,以数组形式返回

      NSArray *images = [NSArray arrayWithContentsOfFile:path];  
  • 懒加载

    • 在开发工程中,为了提高效率,有些数据不一定全部都用上的。所以为了节省内存和提高性能,懒加载就可以满足这样的需求。

       - (NSArray *)images        {           if (_images == nil) {            NSBundle *bundle = [NSBundle mainBundle];            NSString *path = [bundle pathForResource:@"imageData" ofType:@"plist"];            _images = [NSArray arrayWithContentsOfFile:path];        }        return _images;    }
0 0
原创粉丝点击