大写类型在UIAlertController中不起作用

时间:2017-09-30 11:00:49

标签: ios objective-c xcode uitextfield

我正在尝试在alertcontroller的textfield中使用大写。但是我不能让它正常工作。我正在使用UITextAutocapitalizationTypeWords。下面你可以看到我是如何尝试的。

 UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Enter a Name"
                                                                             message:nil
                                                                      preferredStyle:UIAlertControllerStyleAlert];
    [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
        textField.placeholder = @"Title";
        textField.autocapitalizationType = UITextAutocapitalizationTypeWords;

    }];

    UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];

    __weak typeof(self) weakSelf = self;
    UIAlertAction * okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        __strong typeof(self) strongSelf = weakSelf;
        UITextField *nameField = [alertController.textFields firstObject];
        nameField.autocapitalizationType = UITextAutocapitalizationTypeWords;
    }];

    [alertController addAction:cancelAction];
    [alertController addAction:okAction];

0 个答案:

没有答案