Using `textField:shouldChangeCharactersInRange:`, how do I get the text including the current typed character?

前端 未结 10 2045
粉色の甜心
粉色の甜心 2020-12-02 05:23

I\'m using the code below to try and have textField2\'s text content get updated to match textField1\'s whenever the user types in textField1

10条回答
  •  余生分开走
    2020-12-02 06:14

    -shouldChangeCharactersInRange gets called before text field actually changes its text, that's why you're getting old text value. To get the text after update use:

    [textField2 setText:[textField1.text stringByReplacingCharactersInRange:range withString:string]];
    

提交回复
热议问题