Advertisement
ibobah

UIAlertView with TextField like AppStore

Apr 5th, 2012
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (void)mySuperMethodWithAlert
  2. {
  3.  // ... bla bla bla
  4.  
  5.  // создаем и показывем UIAlertView
  6.  //
  7.  
  8.  UIAlertView *alertView = [[UIAlertView alloc] initWithTitle: @"Who are you?"    
  9.                                                         message:@"Give your full name"
  10.                                                        delegate:self  cancelButtonTitle:@"Cancel"  
  11.                                               otherButtonTitles:@"OK", nil];
  12.     // Adds a username Field
  13.     //
  14.     UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 50.0, 260.0, 25.0)];
  15.     textField.placeholder = @"Username";
  16.     [textField setBackgroundColor:[UIColor whiteColor]];
  17.     [alertView addSubview:textField];
  18.  
  19.     [alertView show];
  20.     [alertView release];
  21.     [textField release];
  22.  
  23.  // ... bla bla bla
  24. }
  25.  
  26. // Обрабатываем нажатие кнопки
  27. //
  28. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
  29.     // the user clicked one of the OK/Cancel buttons
  30.     if (buttonIndex == 0)
  31.     {
  32.         UITextField *field = (UITextField *)[[alertView subviews] lastObject];
  33.         NSLog (@"%@", field.text);
  34.     }
  35.     else
  36.     {
  37.         //NSLog(@"cancel");
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement