更改后在字典中附加对象

时间:2012-03-21 06:37:14

标签: uitextfield nsmutabledictionary avaudiorecorder

我正在使用不同的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"];

有人有任何建议吗?

1 个答案:

答案 0 :(得分:0)

变化:

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

为:

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