0

私は数年間うまく機能しているプログラムを持っています。突然、iOS 7 にアップグレードすると、機能しなくなりました。UIAlertView 内の RootViewController に UIAlertView (パスワード ダイアログ) を配置しています。UIAlertView は表示されますが、その中の UITextField は表示されません。これが突然機能しなくなる理由についての手がかりはありますか?

短縮コード:

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    // Some initialization

   if (!firstTimeInit) {
     alert =
        [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Password",
                                                             @"Password") 
                                   message:NSLocalizedString(@"EnterPassword",
                                                             @"EnterPassword") 
                                  delegate:self
                         cancelButtonTitle:nil
                         otherButtonTitles:@"OK", nil];
     alert.frame = CGRectMake( 0, 0, 300, 260);

     UITextField *myTextField =
         [[UITextField alloc] initWithFrame:CGRectMake(32.0f, 75.0f,
                                                       220.0f, 28.0f)];
     myTextField.placeholder = NSLocalizedString(@"Password", @"Password");

     [myTextField setSecureTextEntry:YES];
     [myTextField setBackgroundColor:[UIColor whiteColor]];
     [myTextField setBorderStyle:UITextBorderStyleBezel];
     myTextField.tag = 11;
     [alert addSubview:myTextField];
     CGAffineTransform myTransform =
         CGAffineTransformMakeTranslation(0.0, 75.0);
     [alert setTransform:myTransform];

     [prefs retain];
     [alert show];
     [myTextField becomeFirstResponder];
  }
}
4

2 に答える 2

3

UIAlertViewStyleSecureTextInputテキストフィールドを使用する必要があります。

UIAlertView *alert =
    [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Password",
                                                         @"Password") 
                               message:NSLocalizedString(@"EnterPassword",
                                                         @"EnterPassword")];
alert.alertViewStyle = UIAlertViewStyleSecureTextInput;

デリゲート メソッドで次のようにします。

- (void)alertView:(UIAlertView *)alertView
    didDismissWithButtonIndex:(NSInteger)buttonIndex
{
  NSString *password = [[alertView textFieldAtIndex:0] text];
  // Whatever password processing.

}

サブビューを a に追加することUIAlertViewは UIKit ではサポートされていないため、代わりにサポートされている方法を使用する必要があります:)

于 2013-09-20T23:03:23.477 に答える