ユーザがビューを終了したときに自動的にNSMutableDictionaryをドキュメントディレクトリに保存します。ここで私が実装しようとしているコードです。しかし、それは動作していません。誰かが私を助けることができますか?NSMutableDictionaryをドキュメントディレクトリに保存する
- (void)viewDidUnload
{
NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"audio.caf",@"pictureAudioKey",
@"audio.m4a",@"englishAudioKey",
@"audio2.m4a",@"spanishAudioKey",
@"audio3.m4a",@"frenchAudioKey",
@"audio4.m4a",@"germanAudioKey",
@"audio5.m4a",@"italianAudioKey",
@"audio6.m4a",@"chineseAudioKey",
@"image.jpg",@"photoimagekey",
@"name.txt", @"identity",
@"imagename.txt",@"numberkey",nil];
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [documentPaths objectAtIndex:0];
NSString *dictionaryPath = [documentsDirectory stringByAppendingPathComponent:[[self imageNameTextField]text]];
dictionaryPath =[dictionaryPath stringByAppendingFormat:@"dicitonary" ] ;
NSDictionary *savedDictionary = dictionary;
NSLog(@"The Save file is:%@", savedDictionary);
[savedDictionary writeToFile:dictionaryPath atomically:YES];
[super viewDidUnload];
}
だから私はボタンでそれを置くことによって、ドキュメントディレクトリに保存する辞書を得ました。私は私のドキュメントディレクトリに見ると、このよう は
- (void)saveAction:(id)sender {
NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"audio.caf",@"pictureAudioKey",
@"image.jpg",@"photoimagekey",
@"name.txt", @"identity",
@"imagename.txt",@"numberkey",nil];
NSArray *documentPaths3 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory3 = [documentPaths3 objectAtIndex:0];
NSString *dictionaryPath3 = [documentsDirectory3 stringByAppendingPathComponent:[[self imageNameTextField]text]];
dictionaryPath3 =[dictionaryPath3 stringByAppendingFormat:@"dictionary" ] ;
NSDictionary *savedDictionary2 = dictionary;
NSLog(@"The Save file is:%@", savedDictionary2);
[savedDictionary2 writeToFile:dictionaryPath3 atomically:YES];
それは私はそれがこの
<key>identity</key>
<string>name.txt</string>
<key>numberkey</key>
<string>imagename.txt</string>
<key>photoimagekey</key>
<string>image.jpg</string>
<key>pictureAudioKey</key>
<string>audio.caf</string>
のように見えるテキストの出口でそれを開いたとき 1dictionaryという名前のファイルを持っています
aこのようなif文で辞書をロードしようとしています。
if ((int)index == 0) {
FinalDetailViewController *detailViewController = [[FinalDetailViewController alloc] initWithNibName:@"FinalDetailViewController" bundle:nil];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
//Get a full path to the image in the documents directory.
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:@"1dictionary"];
NSDictionary *myDictionary = [NSDictionary dictionaryWithContentsOfFile:fullPath];
NSMutableDictionary *familyDictionary =[[NSMutableDictionary alloc]initWithDictionary:myDictionary];
/*NSMutableDictionary *familyDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"audio.caf",@"pictureAudioKey",
@"image.jpg",@"photoimagekey",
@"name.txt", @"identity",
@"imagename.txt",@"numberkey",nil];*/
detailViewController.familyDictionary = familyDictionary;
[self.navigationController pushViewController:detailViewController animated:YES];
}
それがキャッチされない例外により 'NSInvalidArgumentException'、理由にアプリを終了
*でのアプリのクラッシュを行っていません: '* - [NSURL initFileURLWithPath:]:ゼロの文字列パラメータ'
私が間違っていることは何ですか?
"それは機能していません"とはどういう意味ですか?コードを実行するとどうなりますか? – jonkroll
私はドキュメントディレクトリ – user1114881
に表示されません(あなたはファイル名の誤りを覚えていますか?間違ったファイルについてdirを探していますか?) –