如何从imageview中显示的plist文件中检索图像数组?

时间:2012-07-12 15:14:29

标签: ios cocoa-touch

如何从plist中检索图像数据并将该数据显示到图像视图?

1 个答案:

答案 0 :(得分:0)

- (void)getImages {

    // Look in Documents for an existing plist file
    NSArray *paths = NSSearchPathForDirectoriesInDomains(
                                                         NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    myPlistPath = [documentsDirectory stringByAppendingPathComponent: 
                   [NSString stringWithFormat: @"%@.plist", plistName] ];
    [myPlistPath retain];

    // If it's not there, copy it from the bundle
    NSFileManager *fileManger = [NSFileManager defaultManager];
    if ( ![fileManger fileExistsAtPath:myPlistPath] ) {
        NSString *pathToSettingsInBundle = [[NSBundle mainBundle] 
                                            pathForResource:plistName ofType:@"plist"];
    }

    NSArray *paths = NSSearchPathForDirectoriesInDomains(
                                                         NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectoryPath = [paths objectAtIndex:0];
    NSString *path = [documentsDirectoryPath 
                      stringByAppendingPathComponent:@"myApp.plist"];
    NSMutableDictionary *plist = [NSDictionary dictionaryWithContentsOfFile: path];

    NSArray *imageArray = [plist objectForKey:@"imageArray"];

    for (NSString *imageString in imageArray) {
        DLog(@"Image Name: %@", imageString);
    }

}

www.iphoneexamples.com

获取plist代码