0
我使用不同的objectsForKeys保存NSMutableArray。 我有三個對象由用戶輸入設置。 我希望能夠添加新的對象文本與.caf和.txt。所以當它們在下一個viewController中被調用時,它們可以被識別和使用。更改後在字典中追加對象
這裏是我的代碼:
- (void)saveAction:(id)sender {
[self.nameTextField resignFirstResponder];
[self.imageNameTextField resignFirstResponder];
NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"main.caf",@"pictureAudioKey",
@"audio1.m4a",@"firstAudioKey",
@"audio2.m4a",@"secondAudioKey",
@"audio3.m4a",@"thirdAudioKey",
@"audio4.m4a",@"fourthAudioKey",
@"audio5.m4a",@"fifthAudioKey",
@"audio6.m4a",@"sixthAudioKey",
@"main.jpg",@"photoimagekey",
@"some.txt", @"identity",
@"imagename.txt",@"numberkey",nil];
//here is where I change the object values by what the user puts into the textfield imagename.text
This works fine especially for the photo since it is recognized as a png without the extension and loaded
[dictionary setObject:[[self imageNameTextField]text]
forKey:@"photoimagekey"];
//However when you strip the .txt from a text file...or the .caf from an audio //file they are not recognized and not loaded.
[dictionary setObject:[[self imageNameTextField]text]
forKey:@"identity"];
//I tried this
//identity=[identity stringByAppendingFormat:@"txt" But it didn't work
NSString *audioString = [dictionary objectForKey:@"pictureAudioKey"];
audioString = [audioString stringByAppendingFormat:@".caf"];
[dictionary setObject:[[self imageNameTextField]text]
forKey:@"pictureAudioKey"];
有沒有人有什麼建議?