gpt4 book ai didi

cocoa - 在 NSTextField 中按下 Enter 键时执行操作?

转载 作者:行者123 更新时间:2023-12-03 16:00:17 26 4
gpt4 key购买 nike

我现在有一个小问题。我想在 NSTextField 中按下 Enter 键时执行一个方法。用户应该能够输入他的数据,并且一旦按下回车键就应该执行计算方法。

最佳答案

您可以通过设置文本字段的操作来完成此操作。在 IB 中,将文本字段的选择器连接到您的 Controller 或任何呈现您要使用的 IBAction 的对象。

要在代码中设置它,请向 NSTextField 发送 setTarget: 消息和 setAction: 消息。例如,如果您在代码中的 Controller 对象上设置此项,并且您的 textField 导出名为 myTextField:

- (void)someAction:(id)sender
{
// do something interesting when the user hits <enter> in the text field
}

// ...

[myTextField setTarget:self];
[myTextField setAction:@selector(someAction:)];

关于cocoa - 在 NSTextField 中按下 Enter 键时执行操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/995758/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com