Problem with NSTextCell subclass
Problem with NSTextCell subclass
- Subject: Problem with NSTextCell subclass
- From: Tyler Berry <email@hidden>
- Date: Wed, 17 Sep 2003 10:38:04 -0600
I've been having trouble with an NSTextCell subclass; I asked for some advice
on Omni's MacOSX-dev list, but didn't get any responses. Hoping for better
success here, I'm trying again.
I'm subclassing NSTextFieldCell to provide NSComboBoxCell-ish autocompletion
without the actual NSComboBox (and associated drop-down menu, etc. I'm
specifically having trouble putting the subclassed cells into NSTableViews.
The subclass seems to work fine inside if put into an NSTextField which has
been setCellTyped to use my cell subclass. However, if I put it into an
NSTableView (uncustomized), I am no longer able to select and edit individual
cells, and after clicking on the table a certain number of times - usually
between 8 and 15 - the program crashes with a SIGSEGV.
The backtrace always shows the offending method as [TBCompletingTextFieldCell
dealloc], and varies seemingly randomly. Sometimes that is the top stack
frame,
and other times there are approximately 5400 stack frames all consisting of
CFRelease (which I assume is the real guts behind the dealloc method of
NSObject).
Secondarily, I have yet to find out the optimal place to insert the code to
actually perform the autocompletion. I have all the code written to handle
scanning the internal array of the cell to find a matching string, but I've
not
yet trapped the actual typing in the cell to attempt to match it.
I know that NSTextFieldCell invokes an NSText field editor to handle the
actual
editing, and that it is the NSText which receives the keyDown: message. Where
should I be looking to override/watch the incoming events to handle the
completion?
Relevant code follows.
The actual subclass (_completes and _usesDataSource are BOOLs, _dataSource is
an id, and _internalList is an NSMutableArray *):
@implementation TBCompletingTextFieldCell : NSTextFieldCell
- (id) initTextCell:(NSString *)string
{
if (self = [super initTextCell:string])
{
_completes = NO;
_usesDataSource = NO;
_dataSource = nil;
_internalList = [[NSMutableArray alloc] init];
}
return self;
}
- (void) dealloc
{
[_internalList release];
[super dealloc];
}
...
The above was also tried with [[NSMutableArray alloc] initWithCapacity:0],
which didn't alter the behavior.
This is the code used to set up the NSTableView to use this cell as the
dataCells for the TableColumns - tableDataSource has an NSArray member:
- (void) displayTable
{
for (i=0; i < [[tableDataSource array] count]; i++)
{
NSTableColumn *column = [[NSTableColumn alloc]
initWithIdentifier:[[dateSource array] objectAtIndex:i]];
...
[table addTableColumn:column];
[column setDataCell:[[TBCompletingTextFieldCell alloc]
initTextCell:@""]];
}
}
I also tried the above with col autoreleased; it didn't change the behavior.
Thanks again and in advance for any help.
--
Tyler Berry
[demime 0.98b removed an attachment of type application/pgp-signature]
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.