detecting the change of content of UITextField when the change is not made by the keyboard

前端 未结 7 1635
挽巷
挽巷 2020-12-30 04:54

I have a UIButton and a UITextField,when the button is pressed the textfield\'s content string will be equal to: This is a test string

7条回答
  •  滥情空心
    2020-12-30 05:42

    Maybe simple key-value observing will work?

    [textField addObserver:self forKeyPath:@"text" options:0 context:nil];
    
    - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
        if([keyPath isEqualToString:@"text"] && object == textField) {
            // text has changed
        }
    }
    

    Edit: I just checked it, and it works for me.

提交回复
热议问题