|
Q: How do I make NSTextField accept the tab key, as well as return and enter keys as line-breaks?A: It's worth noting that So you need to ask yourself "why" you want to keep using NSTextField. Here is a list of possible reasons:
Delegate MethodShould you decide to keep using
The method name Note: When implementing this delegate method in your own object you should set your object up as the "delegate" for this NSTextField. This delegate method is a part of Listing 1: Example delegate method for NSTextField.
- (BOOL)control:(NSControl*)control textView:(NSTextView*)textView doCommandBySelector:(SEL)commandSelector
{
BOOL result = NO;
if (commandSelector == @selector(insertNewline:))
{
// new line action:
// always insert a line-break character and don’t cause the receiver to end editing
[textView insertNewlineIgnoringFieldEditor:self];
result = YES;
}
else if (commandSelector == @selector(insertTab:))
{
// tab action:
// always insert a tab character and don’t cause the receiver to end editing
[textView insertTabIgnoringFieldEditor:self];
result = YES;
}
return result;
}
Note: Notice Listing 1 uses two action methods: For more information on NSTextField and NSTextView refer to - Text Editing Programming Guide for Cocoa: "Working with the Field Editor". Document Revision History
Posted: 2006-10-09 |
|