• 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
Is drawRect really where setShowsFirstResponder should be called?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Is drawRect really where setShowsFirstResponder should be called?


  • Subject: Is drawRect really where setShowsFirstResponder should be called?
  • From: Ricky Sharp <email@hidden>
  • Date: Thu, 23 Dec 2004 18:04:18 -0600

I'm starting to experiment with a multi-cell control. I started out with a single-cell control and provided a drawRect: override. Up until this point, I haven't had to provide a drawRect: for any of my NSControl subclasses.

Now then, my override would be responsible for drawing all of its cells by sending the cells drawWithFrame:inView: messages.

To start slowly, I wanted to make sure my drawRect: override did what the NSControl base class did in the single-cell situation. Here's what was implemented:

- (void)drawRect:(NSRect)aRect
{
    [[self cell] drawWithFrame:[self bounds] inView:self];
}

But, when being rendered, the control that currently has focus is not showing my custom focus ring. The cell actually contains the code to render the focus ring if showsFirstResponder returns YES. I verified that showsFirstResponder returned NO, even though my control did actually have keyboard focus.

If I change the implementation to [super drawRect:aRect], I get the proper focus ring behavior (as I would have expected).

Finally, I changed the implementation to this:

- (void)drawRect:(NSRect)aRect
{
[[self cell] setShowsFirstResponder:([[self window] firstResponder] == self)];
[[self cell] drawWithFrame:[self bounds] inView:self];
}


And now I get the correct behavior.

Is drawRect really the proper place to call setShowsFirstResponder? On the surface, it appears that this is what NSControl's implementation (or inherited imp) is doing.

Would it be more proper to provide overrides for become/resignFirstResponder in my control and set my cell's responder flag in there?
___________________________________________________________
Ricky A. Sharp mailto:email@hidden
Instant Interactive(tm) http://www.instantinteractive.com


_______________________________________________
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


  • Prev by Date: Re: "Can't create new document" alert unwanted
  • Next by Date: Re: Bundling Framework Problem
  • Previous by thread: Re: NSData writeToFile
  • Next by thread: One delegate's method doesn't work
  • Index(es):
    • Date
    • Thread