• 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
Re: Getting info from outside drawRect
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting info from outside drawRect


  • Subject: Re: Getting info from outside drawRect
  • From: email@hidden
  • Date: Wed, 20 Mar 2002 13:55:50 -0800

I'm trying to draw some items (mostly lines) in a customized subclass
NSView. However, when I try and use data members which are in the class
with the drawRect function, the items won't draw. For the app I'm
trying to design, I will want to import several pieces of information,
such as the location of points and an array of NSPoint information.
What modifications do I need to make so things will draw correctly? I
have two classes, one for the Controller and another for the View.

Here is my example drawRect code. This draws correctly, but if I have
my own defined 'bounds' variable, delcared in the MyView.h file.

- (void)drawRect:(NSRect)rect
{
NSRect myBounds = [self bounds];
NSMutableDictionary *attrs = [NSMutableDictionary dictionary];

[[NSColor whiteColor] set];
[NSBezierPath fillRect:myBounds];

// Draw x and y axes
[[NSColor lightGrayColor] set];

[NSBezierPath strokeLineFromPoint: NSMakePoint(0,
(myBounds.size.height/2.0)) toPoint:NSMakePoint(myBounds.size.width,
(myBounds.size.height/2.0))];

[NSBezierPath strokeLineFromPoint:
NSMakePoint((myBounds.size.width/2.0), 0)
toPoint:NSMakePoint((myBounds.size.width/2.0), myBounds.size.height)];

[self drawLine];

// Draw border around the view
[[NSColor blackColor] set];
[NSBezierPath strokeRect:myBounds];
}

I'm not sure I totally understood the problem you're having, but I see one possible problem: It sounds like you're defining an ivar named "bounds"; I wouldn't use that name if I were you, as it is a method defined by Apple as very close to the name of an ivar in NSView (I think the ivar is _bounds, but still). At a minimum, you risk having some interesting interactions with key-value coding with the key "bounds"; your ivar would be used instead of Apple's methods when the "stored value" forms were used. This is probably not the issue, but it's good programming practice to try to maintain a more respectable distance from Apple's variable and mathod names.

Since you posted the version of the code that works, not the version that doesn't work, it's a bit hard to tell what the problem might be, apart from this observation. :->

Ben Haller
Stick Software
_______________________________________________
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: NSProgressIndicator, Hiding and CPU Usage
  • Next by Date: Re: NSImage Questions
  • Previous by thread: Getting info from outside drawRect
  • Next by thread: Script commands and the application object
  • Index(es):
    • Date
    • Thread