【问题标题】:Populating the ImageData.plist in PhotoScroller example在 PhotoScroller 示例中填充 ImageData.plist
【发布时间】:2012-02-22 18:03:14
【问题描述】:

我对 iPhone 应用程序开发还很陌生,我需要您的帮助。我正在尝试使用我自己的图像填充 Apple 的 PhotoScroller example 中的 imageData.plist,您能否指导我如何根据完整图像文件夹中的所有图像以编程方式填充此 plist 文件?我面临的另一个挑战是可以随时将任意数量的未知图像放入文件夹中。下面是 plist 文件的快照。

plist表的定义

第 0 项词典(3 项)
身高 400 号
宽度 编号 290
名称字符串湖
第 1 项字典(3 项)
身高 400 号
宽度 编号 290
名称字符串树
第 2 项词典(3 项)
身高 400 号
宽度 编号 290
名称字符串 棚
第 3 项词典(3 项)
身高 400 号
宽度 编号 290
名称字符串 Rock

我知道我必须使用 NSDictionary 类和 writeToFile 来实现这一点,但是如何去做我需要帮助。

【问题讨论】:

    标签: iphone ios plist nsdictionary writetofile


    【解决方案1】:

    NSDictionarys 数组?

    NSMutableArray *dicts = [NSMutableArray arrayWithCapacity:10];
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:400], @"height", [NSNumber numberWithInt:290], @"width", @"Lake", @"name", nil];
    [dicts addObject:dict];
    //and so on...
    
    NSFileManager *fileManager = [NSFileManager defaultManager];
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"filename.plist"];
    
    [dicts writeToFile:filePath atomically:YES];
    

    【讨论】:

      猜你喜欢
      • 2012-01-10
      • 2012-09-25
      • 2012-01-10
      • 2019-05-26
      • 2015-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多