Reputation: 570
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];
}
}
Upvotes: 3
Views: 576
Reputation: 22930
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];
Upvotes: 2