3

i have alert window with text field and 2 buttons, i need to save text added in my text field to .plist file, how can i do these?

.h file

NSMutableDictionary *cameras;

my alert code

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(buttonIndex == [alertView firstOtherButtonIndex])
    {
        NSString *plistPath = [DOCUMENTS stringByAppendingPathComponent:@"Cameras.plist"];
        NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:cameras format:NSPropertyListXMLFormat_v1_0 errorDescription:nil];
        if(plistData)
            [plistData writeToFile:plistPath atomically:YES];
    }
}
Marcus Adams
  • 53,009
  • 9
  • 91
  • 143
Roman Simenok
  • 530
  • 7
  • 22
  • What part of this do you need help with? 1) Getting the text from the alert? 2) Creating the data to write? 3) Writing the plist file? – rmaddy Aug 13 '13 at 15:29

1 Answers1

2

Take text from text field. Create one NSDictionary, and write to File.

UITextField *textfield = [alertView textFieldAtIndex:0];
NSString *value =   [textfield text];
NSDictionary *dictionary = [[NSDictionary alloc] initWithObjects:value forKeys:@"key"];
[dictionary writeToFile:path atomically:YES];
Parag Bafna
  • 22,812
  • 8
  • 71
  • 144