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

前端 未结 10 2035
粉色の甜心
粉色の甜心 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:05

    My solution is to use UITextFieldTextDidChangeNotification.

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(copyText:) name:UITextFieldTextDidChangeNotification object:nil];
    

    Don't forget to call [[NSNotificationCenter defaultCenter] removeObserver:self]; in dealloc method.

提交回复
热议问题