kamilosxd678

asdasd

May 7th, 2013
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. NSLog(@"Zapisuję preferencję użytkownika.");
  2.  
  3. //alert
  4. NSString *prompt = @"Alert";
  5. NSString *infoText = @">UserDefaults<";
  6. NSString *defaultValue = @"Wpisz tekst:";
  7.  
  8. NSAlert *alert = [NSAlert alertWithMessageText: prompt
  9. defaultButton:@"Save"
  10. alternateButton:@"Cancel"
  11. otherButton:nil
  12. informativeTextWithFormat:@"infoText"];
  13. //textfield
  14. NSTextField *mojTekst = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 200, 24)];
  15. [mojTekst setStringValue:defaultValue];
  16. //wstawienie textfield do alerta
  17. [alert setAccessoryView:mojTekst];
  18.  
  19. //określenie akcji po wyjściu z alerta
  20. NSInteger wyswietlenie = [alert runModal];
  21.  
  22. if (wyswietlenie == NSAlertDefaultReturn) {
  23. NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
  24. [def setValue:mojTekst.stringValue forKey:@"mojKlucz"];
  25. [def synchronize];
  26. NSLog(@"Zapisano preferencję użytkownika.");
  27. } else if (wyswietlenie == NSAlertAlternateReturn) {
  28. NSLog(@"Anulowano.");
  29. } else {
  30. NSLog(@"Błąd.");
  31. }
Advertisement
Add Comment
Please, Sign In to add comment