Xcode8 iOS9 UIAlertController textfield disapear(iOS8& 10是正常的)

时间:2017-03-06 06:07:35

标签: uitextfield ios9 xcode8 uialertcontroller

Xcode 8 iOS9 UIAlertController文本消失。 在从Xcode7迁移到Xcode8之前,在iOS9上运行应用程序时没有任何问题。

  1. iOS9 UIAlertController With UITextfield
  2. iOS10 UIAlertController With UITextfield
  3. 有没有人有这个问题?

    UIAlertController * alertController = [UIAlertController alertControllerWithTitle:@“mile”message:nil preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:getLocalizationString(@"cancel") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
          [[NSNotificationCenter defaultCenter] removeObserver:self name:UITextFieldTextDidChangeNotification object:nil];
    }];
    [alertController addAction:cancelAction];
    
    @weakify(alertController);
    @weakify(self);
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:getLocalizationString(@"ok") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
          [[NSNotificationCenter defaultCenter] removeObserver:self name:UITextFieldTextDidChangeNotification object:nil];
        @strongify(alertController);
        @strongify(self);
        UITextField *textField = alertController.textFields.firstObject;
        self.totalMileage = textField.text;
        self.mileageLabel.text = self.totalMileage;
        if (self.start2DriveDateTime&&![self.start2DriveDateTime isEqualToString:@""]) {
            [self getRecommendMaintenanceList];
        }
    }];
    okAction.enabled = (self.totalMileage&&![self.totalMileage isEqualToString:@""]);
    [alertController addAction:okAction];
    
    
    [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField){
        @strongify(self);
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(alertTextFieldDidChange:) name:UITextFieldTextDidChangeNotification object:textField];
        textField.placeholder = @"mile";
        textField.keyboardType =UIKeyboardTypeNumberPad;
        textField.text = self.totalMileage;
        textField.delegate = self;
    }];
    [self.navigationController presentViewController:alertController animated:YES completion:nil];
    

0 个答案:

没有答案