2013-08-13 2 views
3

У меня есть окно предупреждения с текстовым полем и 2 кнопками, мне нужно сохранить текст, добавленный в текстовое поле, в файл .plist, как я могу это сделать?Как сохранить значение текстового поля UIAlertView в файл .plist?

.h файл

NSMutableDictionary *cameras; 

мой бдительный код

-(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]; 
    } 
} 
+0

С каковой частью вам нужна помощь? 1) Получение текста из предупреждения? 2) Создание данных для записи? 3) Написание файла plist? – rmaddy

ответ

2

text Возьмите из текстового поля. Создайте один NSDictionary и напишите в файл.

UITextField *textfield = [alertView textFieldAtIndex:0]; 
NSString *value = [textfield text]; 
NSDictionary *dictionary = [[NSDictionary alloc] initWithObjects:value forKeys:@"key"]; 
[dictionary writeToFile:path atomically:YES]; 
+1

Почему stringValue, а не текст? stringValue не является свойством UITextField – giorashc

+0

@giorashc Обновлено. –

Смежные вопросы