• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Problems subclassing NSTextField
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problems subclassing NSTextField


  • Subject: Problems subclassing NSTextField
  • From: Kalle Soiha <email@hidden>
  • Date: Fri, 22 Nov 2002 18:15:05 +0200

Hello everyone. I'm developing my first major Cocoa app and got a small problem that I cannot seem to solve on my own. Perhaps you guys could give me a hand?

In my app, I have a single NSTextField that serves as a command line of sorts: user types a command, the command is executed and the command line is cleared so the user can input a new command. Everything works great. Now I want to implement a command line history feature (while the command line is in focus, the up and down arrow keys select through previously entered commands).

My plan was simple: subclass NSTextField and override the -keyDown: method. In my new -keyDown: I just check if the arrow keys are pressed and if they are, then I scroll through the history. Otherwise I just do [super keyDown:theEvent] so the original NSTextField implementation can take care of things for me. This should work, since NSTextField is itself a subclass of NSResponder, right?

Good and simple plan, yes, except that it does not work. My own -keyDown: -method is not even called and the control works just like a regular NSTextField. I cannot even seem to *break* the control in any way (I tried - among other things - to make -becomeFirstResponder: return NO), it just seems like all my valiant attempts at subclassing are ignored. Even my own -initWithFrame: initialization method doesn't get called. HOWEVER, if I use Interface Builder to connect something (say, a button) into one of my own action methods in my class, they DO get called. This bugs me enormously, since IB obviously knows about the new class and it's definitions, but all methods that are overridden don't seem to have any effect.

Questions:

1) Why don't my overridden functions get called? Is there something about the event mechanism here that I am missing?

2) Do I have to do something else in Interface Builder besides placing the NSTextField control on my window and changing its class name from the info palette (Opt-5 and select my own class name)?

and most importantly,

3) How do I fix this? :-)

Any help would be greatly appreciated. Thanks in advance!
_______________________________________________
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.

  • Prev by Date: RE: multiple componentsSeparatedByString
  • Next by Date: RE: multiple componentsSeparatedByString
  • Previous by thread: Text color of dragged rows in NSTableView
  • Next by thread: Re: Problems subclassing NSTextField
  • Index(es):
    • Date
    • Thread