Ignore Tab character in UITextField… (iPad app)

前端 未结 5 762
难免孤独
难免孤独 2021-01-17 09:39

I have a TableView with TextFields in each cell and I want to those textfields ignore the character tab (\\t).

When the tab key is pressed, the t

5条回答
  •  长发绾君心
    2021-01-17 10:15

    This seems to be a problem with the tab (\t) character. This character is not handled like normal characters (e.g. a, b, c, 0, 1, 2, ...) and thus the

                  - (BOOL)textField:(UITextField *)textField 
      shouldChangeCharactersInRange:(NSRange)range 
                  replacementString:(NSString *)string;
    

    delegate method won't ever be called.

    The result of using a tab on e.g. an external keyboard or in the simulator is that a currently active textfield resigns it's first responder status and the result of

    [textField nextResponder]
    

    will become first responder instead.

    What IMO currently is a bug (iOS SDK 4.3) is that the delegate method

    - (BOOL)textFieldShouldEndEditing:(UITextField *)textField
    

    is only called once (when you return yes) and when you reselect the same textfield and use the tab key again, the method won't be called again.

提交回复
热议问题