2012-03-21 18 views
0

NSMutableArrayを別のobjectsForKeysで保存しています。 私は3つのオブジェクトをユーザーが入力して設定しています。 新しいオブジェクトテキストを.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"]; 

誰もが何か提案がありますか?

答えて

0

変更:

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

へ:

[dictionary setObject:[NSString stringWithFormat:@"%@.txt", [[self imageNameTextField] text]] 
       forKey:@"identity"]; 
関連する問題