1

下に保存されているファイルを取得するにはどうすればよいですか?

-(NSString *) dataFilePath
{
    NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentDirectory = [path objectAtIndex:0];
    return [documentDirectory stringByAppendingPathComponent:@"Answer.plist"];
}

NSString *filePath = [self dataFilePath];
    if ([[NSFileManager defaultManager] fileExistsAtPath:filePath])
    { NSArray *array = [[NSArray alloc] initWithContentsOfFile:filePath];
        NSLog(@"%@\n",array);
        NSLog(@"%@\n", filePath);
    }

アイテムを上書きせずにplistに追加する方法はありますか?

4

1 に答える 1

1

これを使用できます:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
        NSString *documentsDirectory = [paths objectAtIndex:0]; 
        path = [documentsDirectory stringByAppendingPathComponent:@"Answer.plist"];

        NSMutableArray *array = [[NSMutableArray alloc] initWithContentsOfFile:path];
        NSLog(@"array, %@",array);
        [array removeObjectAtIndex:yourIndex];

また

[array addObjectAtIndex:yourIndex];

[array writeToFile:path atomically:YES];
于 2012-08-10T06:02:39.207 に答える