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

后端 未结 8 1932
野的像风
野的像风 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:34

    In your delegate (NSTextFieldDelegate), add the following:

    -(void)controlTextDidEndEditing:(NSNotification *)notification
    {
        // See if it was due to a return
        if ( [[[notification userInfo] objectForKey:@"NSTextMovement"] intValue] == NSReturnTextMovement )
        {
            NSLog(@"Return was pressed!");
        }
    }
    

提交回复
热议问题