2013-09-27 3 views
0

UIAlertView с UITextField, не работающим в iOS 7. Как исправить?Проблема UITextField в iOS 7

Вот ScreenShot:

enter image description here Вот мой код:

Как я могу получить UITextFeield в UIAlertView в iOS7?

-(void)takeUserName 
{ 
     mChangePlayerAlert = [[UIAlertView alloc] init]; 
     mChangePlayerAlert.title = title; 
     mChangePlayerAlert.message = @"\n"; 
     mChangePlayerAlert.delegate = self; 
     [mChangePlayerAlert addButtonWithTitle:@"Save"]; 
     [mChangePlayerAlert addButtonWithTitle:@"Cancel"]; 

     CGRect frame; 
     frame = CGRectMake(20, 45, 245, 27);//(200, 500, 400, 120); 

     mTextFeild = [[UITextField alloc] initWithFrame:frame]; 
     mTextFeild.textColor = [UIColor blueColor]; 
     mTextFeild.borderStyle = UITextBorderStyleRoundedRect; 

     mTextFeild.keyboardType = inType;//; 
     mTextFeild.returnKeyType = UIReturnKeyDone; 
     mTextFeild.autocorrectionType = UITextAutocorrectionTypeNo; 
     mTextFeild.autocapitalizationType = UITextAutocapitalizationTypeNone; 
     mTextFeild.delegate = self; 

     [mChangePlayerAlert addSubview:mTextFeild]; 

     mTextFeild.delegate = self; 
     [mTextFeild becomeFirstResponder]; 

     [mChangePlayerAlert show]; 
} 

ответ

2

Нельзя использовать текстовое представление.

mChangePlayerAlert.alertViewStyle = UIAlertViewStylePlainTextInput;

Чтобы получить значение позже, используйте textFieldAtIndex: в предупредительном зрении делегата:

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex 
{ 
    if(buttonIndex != alertView.cancelButtonIndex) 
    { 
     NSString* text = [alertView textFieldAtIndex:0].text; 

     ... 
    } 
} 
+1

См. Редактирование моего ответа. –

+0

wow..its работает спасибо ... одна небольшая проблема, в прошлый раз я использовал shouldChangeCharactersInRange textFeild делегировать, чтобы ограничить количество текста. Теперь, когда делегат не звонит ... как я могу ограничить количество текста в этом текстовом поле? – iPhoneProcessor

+1

Вы можете. Перед отображением представления предупреждения установите делегат '[alertView textFieldAtIndex: 0]' как свой собственный. Теперь, как и раньше, вы будете вызваны, когда пользователь добавит символы. –

1

если выше ответа не работает для вас попробовать это

[txtvwMessage setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight]; 

Вообще iOS6 к конверсии iOS7 теряет элементы управления дизайном. Вот почему Autosizing концепция здесь, чтобы помочь вам в преобразовании

2

Вы можете использовать пользовательские оповещения View Вместо и добавить любой контент вы хотите там: Custom iOS 7 Alert View

0

Попробуйте это.

- (IBAction)showAlert:(id)sender 
{ 
    UIAlertView *alertView = [[UIAlertView alloc] init]; 

    switch (((UIButton *)sender).tag) 
    { 
    // Default Alert View 
    case 1001: 

     alertView.title = @"Default Alert View"; 
     alertView.message = @"UIAlertViewStyleDefault"; 
     [alertView addButtonWithTitle:@"OK"]; 

     break; 

    // Secure Alert View 
    case 1002: 

     alertView.title = @"Secure Alert View"; 
     alertView.message = @"UIAlertViewStyleSecureTextInput"; 
     alertView.alertViewStyle = UIAlertViewStyleSecureTextInput; 
     [alertView addButtonWithTitle:@"OK"]; 
     [alertView addButtonWithTitle:@"Cancel"]; 

     break; 

    // Plain Alert View 
    case 1003: 

     alertView.title = @"Plain Alert View"; 
     alertView.message = @"UIAlertViewStylePlainTextInput"; 
     alertView.alertViewStyle = UIAlertViewStylePlainTextInput; 
     [alertView addButtonWithTitle:@"OK"]; 
     [alertView addButtonWithTitle:@"Cancel"]; 

     break; 

    // Login ALert View 
    case 1004: 

     alertView.title = @"Login Alert View"; 
     alertView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput; 
     [alertView addButtonWithTitle:@"OK"]; 
     [alertView addButtonWithTitle:@"Cancel"]; 

     break; 
    } 

    [alertView show]; 
} 
Смежные вопросы