开发者

Objective C NSTextField keeps text in box highlighted when command is sent

开发者 https://www.devze.com 2023-01-06 04:22 出处:网络
When I press enter on an NSTextField to send what ever\'s in the text field, it sends it, but highlights what ever\'s in the NSTextField. Does anyone know how to make it so that once it sends the comm

When I press enter on an NSTextField to send what ever's in the text field, it sends it, but highlights what ever's in the NSTextField. Does anyone know how to make it so that once it sends the comma开发者_如何学Gond in, it deletes what ever's in the NSTextField?

Thanks, Elijah


If you haven't already, assign a target and action to the text field. Here's your action method:

- (IBAction)sendText: (id)sender {
    // Whatever else you were doing.
    // ...

    // Add this:
    [sender setStringValue: @""];
    // Optionally, to make it *not* the first responder:
    [[sender window] makeFirstResponder: nil];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消