Re: NSTextField subclass needs cell subclass as well - how?
Re: NSTextField subclass needs cell subclass as well - how?
- Subject: Re: NSTextField subclass needs cell subclass as well - how?
- From: Graham Cox <email@hidden>
- Date: Thu, 08 Oct 2015 15:08:53 +1100
> On 8 Oct 2015, at 2:33 pm, Quincey Morris <email@hidden> wrote:
>
> These statements sound a bit contradictory to me, but never mind.
Well, they shouldn’t be, I daresay my usual inabilty to express these things is getting in the way. My interface is very dynamic, with many different ‘panels’ that can be placed into a window according to some context. Each panel is a view managed by a NSViewController which loads its interface from a separate nib. These panels could have many text fields, most of which are the custom kind, but some are standard. Because of this dynamic loading, the window delegate of the host window(s) isn’t a good place to try and figure out what dynamic stuff is loaded at any given time.
The window doesn’t know or care about this dynamic stuff - it’s largely autonomous and independent of the window and its controller.
Likewise the dynamic stuff itself, those nib files can’t know anything about the window into which they’re ultimately loaded. There’s no reference that could be connected in IB even if this was a good idea, which it isn’t.
> You’re asking about swapping out the cells of text fields programmatically. Is is technically impossible for you to swap out the text fields themselves? (If necessary, by loading the affected controls uncustomized at first, then replacing them with customized ones loaded from a text field nib that has a custom cell set in IB?)
It might be technically feasible, but it sounds like the cure is worse than the disease :)
I’ve tried swapping out the text field’s cell by creating a subclass and copying all of the original settings into it. Unfortunately that doesn’t work - just copying across the state isn’t enough to make the replacement cell look and act like the original text field cell, for some reason - presumably there’s some order-dependent setup or other hidden stuff in the ‘real’ text field cell that I can’t get at.
I haven’t tried swapping the text field itself but it seems probable that would suffer the same fate - I’d have to copy all the state from the ‘real’ field and it doesn’t seem likely that’s going to work perfectly.
-[NSCell fieldEditorForView:] does exactly what I need. Only that it’s a cell method, not a control method. That’s the sole reason I need a custom text field cell, so I can override this method. If this had a cover method on NSControl, I wouldn’t have to do that. As cells go away, a cover method is going to be needed to maintain the same functionality, it just doesn’t seem to exist yet (or is private).
Radar time.
—Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden