Customising the behaviour of an NSTextFieldCell in an NSTableView
Customising the behaviour of an NSTextFieldCell in an NSTableView
- Subject: Customising the behaviour of an NSTextFieldCell in an NSTableView
- From: Jake Macmullin <email@hidden>
- Date: Fri, 7 Jan 2005 10:30:18 +1100
I'm just getting back in to Cocoa after a bit of a hiatus - and I'm
still quite new to Objective-C, so please regard my questions in that
light.
I'd like to customise the behaviour of an NSTextFieldCell that I'm
using in an NSTableView. Basically, I want to do two things:
1). provide my own set of suggestions when complete: is called
2). call complete: after each key-stroke in the cell
I've had limited success so far. To achieve #1 I understand that I need
to provide a delegate for the NSTextField contained by the
NSTextFieldCell - my only problem is, I don't know how to get a
reference to this NSTextField in order to call its setDelegate method.
I've read through the list archives, consulted the API docs, and of
course referred my questions to Google, but there seems to be some
conflicting information. The API docs for NSTextFieldCell describe a
method:
setUpFieldEditorAttributes:
- (NSText *)setUpFieldEditorAttributes:(NSText *)textObj
You never invoke this method directly; by overriding it, however, you
can customize or replace the field editor. When you override this
method, you should generally invoke the implementation of super and
return the textObj argument.
From my reading of this, it seems like I could create an instance of an
NSTextField, call setDelegate on it and then call
setUpFieldEditorAttributes: on my NSTextFieldCell with the NSTextField
instance. However, other posts such as this one from j o a r suggest
that setUpFieldEditorAttributes: might not be the best way to achieve
this:
* Although the documentation for "setUpFieldEditorAttributes:" statesĀ
that it can be used for replacing the field editor, I've never done itĀ
that way - and it's not mentioned here:
<http://developer.apple.com/documentation/Cocoa/Conceptual/WinPanel/
Tasks/UsingWindowFieldEditor.html>
As for #2, I've gone down the path of subclassing NSTextFieldCell so I
can call complete: after each key-stoke. My first instinct was to call
it from the textDidChange method - but that leads to all sorts of nasty
loops (as complete: results in a call to textDidChange:) - so after
some reading of previous similar questions - I thought I might override
keyDown - however whilst NSTextField has a keyDown method,
NSTextFieldCell does not - so this brings me back to needing a
reference to the NSTextField contained within the NSTextFieldCell...
Has anyone done this before?
Is subclassing NSTextField the best way to achieve this - or can I
somehow achieve it by using delegates?
Any help would be appreciated.
Thanks,
Jake MacMullin
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden