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]);
}
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 ofNSControl
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.
精彩评论