开发者

Cocoa's TextField returns action control

开发者 https://www.devze.com 2023-02-16 14:55 出处:网络
I have a TextField (IBOutlet NSTextField *commandInput;) to get an input as a command, and I have a Button to run the command by calling this method:

I have a TextField (IBOutlet NSTextField *commandInput;) to get an input as a command, and I have a Button to run the command by calling this method:

- (IBAction) runShell: (id)sender;
{
    // get the string from inputItem
    NSString* item = [commandInput stringValue];

    system([item UTF8String]);
    NSLog(@"%s", [item UTF8String]);
} 

Cocoa's TextField returns action control

Can I remove the Button? I mean,开发者_开发百科 can I run the runShell method when I hit enter in the TextField?


Yes. The documentation says so explicitly:

An NSTextField object is a kind of NSControl that displays text that the user can select or edit and that sends its action message to its target when the user presses the Return key while editing.

0

精彩评论

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