Re: NSTextField & sizeToFit
Re: NSTextField & sizeToFit
- Subject: Re: NSTextField & sizeToFit
- From: Andre Lipinski <email@hidden>
- Date: Mon, 11 Jun 2001 15:28:30 -0400
On Monday, June 11, 2001, at 12:20 AM, Russell Ahrens wrote:
It's ugly, but what I did to make it work is the following:
- (void)textDidChange:(NSNotification *)notification {
// temporary string to hold the current value of the NSTextField
// and to plop it back in to fool the ?event loop? ?the TextField?
// well, SOMETHING into thinking that the text should be resized now
NSString * temp;
// only size the field as wide as it needs to be, no more
[field sizeToFit];
// inform the display system that the field is ready for redisplay
[field setNeedsDisplay:YES];
// crazy hacktastic way to REALLY make the system redisplay
temp = [field stringValue];
[field setStringValue:temp];
}
There has GOT to be a better way. I haven't found it yet; I would think
that just sizeToFit followed by setNeedsDisplay should be enough.
Hopefully someone more experienced can correct me?
This only works for me when I make the field smaller than it was
previously. The thing is the cell doesn't get larger, or doesn't realise
it must re-display a larger area. I've tried the various NSCell routines
to get it to recalculate its drawing space, but it won't do as I ask.
I wonder now if this is a bug?
Andre