четверг, 5 апреля 2012 г.

UIAlertView с TextField как в AppStore


- (void)mySuperMethodWithAlert
{
 // ... bla bla bla

 // создаем и показывем UIAlertView
 //

 UIAlertView *alertView = [[UIAlertView alloc] initWithTitle: @"Who are you?"     
                                                        message:@"Give your full name" 
                                                       delegate:self  cancelButtonTitle:@"Cancel"   
                                              otherButtonTitles:@"OK", nil]; 
    // Adds a username Field
    //
    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 50.0, 260.0, 25.0)]; 
    textField.placeholder = @"Username";
    [textField setBackgroundColor:[UIColor whiteColor]]; 
    [alertView addSubview:textField];

    [alertView show];
    [alertView release];
    [textField release];

 // ... bla bla bla
}

// Обрабатываем нажатие кнопки
//
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    // the user clicked one of the OK/Cancel buttons
    if (buttonIndex == 0)
    {
        UITextField *field = (UITextField *)[[alertView subviews] lastObject];
        NSLog (@"%@", field.text);
    }
    else
    {
        //NSLog(@"cancel");
    }
}


Комментариев нет:

Отправить комментарий