Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

tmeehan

macrumors newbie
Original poster
Feb 25, 2009
12
0
Does anyone know how to support multi-line text fields in a TableView? I can see how to do it with a NSTextField. In that case you can use the delegate methods to control the behavior. But the NSTableColumn implements NSTextFieldCell not NSTextField. You would think one would inherite from the other but it is not the case.

I really need to be able to enter more than one line of text (not text wrapping) delimited with carriage returns. Any help with this would be greatly appreciated.

Thanks.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
You probably need to subclass NSTextFieldCell and mess with the editing frame methods. editWithFrame:inView:editor:delegate:event: might be what you need.
 

tmeehan

macrumors newbie
Original poster
Feb 25, 2009
12
0
May have solved it myself, but thanks for you suggestion.:)

For those who may struggle with this, here is what I did.

When I discovered what the window's field editor is all about I was convinced that is what I needed to use. I guess each window has a default field editor which is a TextView that sits around and handles the text editing functions for all of the text related items in the window. Sort of an invisisble TextView that does the heavy lifting. It's behavior can be modified via it's delegate methods.

1) Subclass textView and override the textView:doCommandBySelector: method as such:

- (BOOL)control:(NSControl *)control textView:(NSTextView *)fieldEditor doCommandBySelector:(SEL)commandSelector {
BOOL retval = NO;
if (commandSelector == @selector(insertNewline:)) {
retval = YES;
[fieldEditor insertNewlineIgnoringFieldEditor:nil];
}
return retval;
}

2) Override the window delegate's windowWillReturnFieldEditor:toObject: method. Here's my code:

-(id)windowWillReturnFieldEditor:(NSWindow *)sender toObject:(id)anObject
{
if ([anObject isKindOfClass:[ListBoxControl class]])
{
return [[[myTextView alloc] init] autorelease];
}
return nil;
}

In my case the only class instance that I wanted to modify the behavior for was an instance of class ListBoxControl. If the object requesting text editing services is any other than of class type ListBoxControl, then my custom field editor is not used and the default field editor is used.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.