我正在尝试在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];