0

プロパティリストファイルに保存しようとしましたが、オブジェクトを実際のファイル自体ではなく配列に保存するだけなので機能しません。つまり、保存したものが明らかに永続化されていません。

[[category objectAtIndex:questionCounter] replaceObjectAtIndex:5 withObject:myString];
[category writeToFile:filePath atomically:YES];

以前にこれを使用して、プロパティ リスト ファイルをドキュメント ディレクトリに保存し、編集して保存できるようにしました。

NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *plistFilePath = [documentsDirectory stringByAppendingPathComponent:fileNameFull];

if([[NSFileManager defaultManager] fileExistsAtPath:plistFilePath]) {

    category = [NSMutableArray arrayWithContentsOfFile:plistFilePath];

    NSLog(@"Files exist.");

}
else {

    filePath = [[NSBundle mainBundle] pathForResource:fileNamer ofType:@"plist"];
    category = [NSMutableArray arrayWithContentsOfFile:filePath];

    NSLog(@"Files have been created.");

}

プロパティ リストは配列で構成されており、それらの配列内にオブジェクト (文字列) を保存しようとしています。些細なことのような気がしますが、見分けがつきません。

4

1 に答える 1

2

配列を保存しようとしているとき、filePathどのポイントをメインのバンドル ディレクトリに渡しているので、書き込みできません。plistFilePath代わりに次のように使用します。

[category writeToFile:plistFilePath atomically:YES];
于 2012-10-05T19:14:04.507 に答える