iPhone:在UITextField上禁用自动上限/自动更正的问题

时间:2010-03-19 03:34:03

标签: ios objective-c iphone uitextfield

出于某种原因,即使我禁用自动上限和自动更正我的UITextField,它仍然是我输入的第一个字母的大写。

以下是代码:

UITextField* textField = [[[UITextField alloc] initWithFrame:CGRectMake(90.0, 10.0, 213.0, 25.0)] autorelease];
[textField setClearButtonMode:UITextFieldViewModeWhileEditing];
textField.returnKeyType = UIReturnKeyGo;
textField.autocorrectionType = FALSE;
textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
textField.delegate = self;
if (inputFieldType == Email) {
    label.text = @"Email:";
    textField.keyboardType = UIKeyboardTypeEmailAddress;
    emailTextField  = textField;
    textField.placeholder = @"Email Address";
} else { // password
    textField.secureTextEntry = TRUE;
    label.text = @"Password:";
    if (inputFieldType == Password){
        textField.placeholder = @"Password";
        passwordTextField  = textField;
    }
    if (inputFieldType == ConfirmPassword){
        textField.placeholder = @"Confirm Password";
        confirmPasswordTextField  = textField;
    }

}

查看截图: alt text http://grab.by/39WE

6 个答案:

答案 0 :(得分:65)

您将autocorrectionType设置为FALSE,就像它是BOOL一样,但实际上它的类型为UITextAutocorrectionType。因此FALSE被解释为UITextAutocorrectionTypeDefault,这意味着可能启用了自动更正。

我打赌它在你的地址簿中找到了“Phil”的名字,并自动修正了大写以匹配。

答案 1 :(得分:35)

目标 - C

-(void)textFieldDidBeginEditing:(UITextField *)textField
{
    textField.autocorrectionType = FALSE; // or use  UITextAutocorrectionTypeNo
    textField.autocapitalizationType = UITextAutocapitalizationTypeNone;

}

<强>夫特

func textFieldDidBeginEditing(textfield : UITextField)
{
    textField.autocorrectionType = .No
    textField.autocapitalizationType = .None
    textField.spellCheckingType = .No
}

<强> Swift3

  func textFieldDidBeginEditing(_ textField : UITextField)
{
    textField.autocorrectionType = .no
    textField.autocapitalizationType = .none
    textField.spellCheckingType = .no
}

答案 2 :(得分:7)

yourTextFieldName.autocorrectionType = UITextAutocorrectionTypeNo;
yourTextFieldName.autocapitalizationType = UITextAutocapitalizationTypeNone;

答案 3 :(得分:2)

斯威夫特2:

textField.autocorrectionType = .No
textField.autocapitalizationType = .None

答案 4 :(得分:1)

如果您希望在整个项目的UITextField上禁用自动上限/自动更正,则

然后创建一个将继承UITextField类的类,并且init方法将autoCorrectionType设置为“ no”。

function Forhere(agent){
    const{
      forhere, howmanypeople, whattime, namelist
    } = agent.parameters;
    const data1 = [{
      Forhere: forhere,
      HowManyPeople: howmanypeople,
      Time: whattime,
      Name: namelist
    }];
    axios.post('......', data1);
  }





{/*....This code is a result of test(second one)
  "responseId": "d0f44937-e58a-4b71-b6dc-ec2d6c39337b-f308a5c4",
  "queryResult": {
    "queryText": "黃大哥",
    "parameters": {
      "forhere": [
        "內用"
      ],
      "howmanypeople": [
        2
      ],
      "whattime": [
        **{
          "date_time": "2019-09-19T14:00:00+08:00"
        }**
      ],
      "namelist": [
        "黃大哥"
      ]
    },
    "allRequiredParamsPresent": true,
    "outputContexts": [
      {
        "name": "projects/test-tyrpxs/agent/sessions/5dd26d5c-bd99-072c-3693-41f95a3a348d/contexts/forhere",
        "lifespanCount": 4,
        "parameters": {
          "howmanypeople": [
            2
          ],
          "namelist.original": [
            "黃大哥"
          ],
          "howmanypeople.original": [
            "2"
          ],
          "forhere": [
            "內用"
          ],
          "whattime.original": [
            "明天下午2點"
          ],
          "welcome": "嗨",
          "whattime": [
            {
              "date_time": "2019-09-19T14:00:00+08:00"
            }
          ],
          "namelist": [
            "黃大哥"
          ],
          "welcome.original": "hi",
          "forhere.original": [
            "內用"
          ]
        }
      }
    ],
    "intent": {
      "name": "projects/test-tyrpxs/agent/intents/ec0f55c4-e9c9-401f-bce7-d2478c40fb85",
      "displayName": "ForHere"
    },
    "intentDetectionConfidence": 1,
    "diagnosticInfo": {
      "webhook_latency_ms": 4992
    },
    "languageCode": "zh-tw"
  },
  "webhookStatus": {
    "code": 4,
    "message": "Webhook call failed. Error: Request timeout."
  }
}

然后在情节提要中将textfield的cusotom类设置为AppTextField。

enter image description here

答案 5 :(得分:0)

更新了Swift 5的正确答案

    textField.autocorrectionType = .no
    textField.autocapitalizationType = .none
    textField.spellCheckingType = .no