добавление объекта в словарь после его изменения - PullRequest
0 голосов
/ 21 марта 2012

Я сохраняю 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"];

У кого-нибудь есть предложения?

1 Ответ

0 голосов
/ 21 марта 2012

Изменение:

[dictionary setObject:[[self imageNameTextField]text]
               forKey:@"identity"];

на:

[dictionary setObject:[NSString stringWithFormat:@"%@.txt", [[self imageNameTextField] text]] 
               forKey:@"identity"];
...