Execute an Action when the Enter-Key is pressed in a NSTextField?

后端 未结 8 1973
野的像风
野的像风 2020-12-02 06:23

I have a small problem right now. I want to execute a method when the Enter key is pressed in a NSTextField. The user should be able to enter his data and a calculation meth

8条回答
  •  日久生厌
    2020-12-02 06:40

    Best way to do that is to bind the NSTextField value with NSString property.

    For Example,define a method:

    (void)setTextFieldString:(NSString *)addressString {}
    

    add bindings:

    [textField bind:@"value" toObject:self withKeyPath:@"self.textFieldString" options:nil];
    

    Enter any text and hit the return key, setTextFieldString will be called.

提交回复
热议问题