Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

rand0m3r

macrumors regular
Original poster
Jun 30, 2006
115
1
Hi, i'm trying to use this method for an NSAttributedString object. but when i go [object drawAtPoint:p], I get a warning that says there are two definitions of this method, and it is trying to use the one with the signature -(BOOL)drawAtPoint:(NSPoint)aPoint which is not what I want. So how do I get it to use the -(void)drawAtPoint:(NSPoint)aPoint one? thanks.
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
What variable type is object?

If it's id then that may be the problem as both NSString and NSImage define a method with this name. Note that the correct one will actually be chosen at run time, but if you want to get rid of the warning try:

Code:
[((NSAttributedString *) object) drawAtPoint:aPoint];

This will allow the compiler to know the type of the object so which version method to call...
 

rand0m3r

macrumors regular
Original poster
Jun 30, 2006
115
1
i made a set of NSAttributedString objects and put it an NSMutableArray and then tried to get them back with objectAtIndex. So they should be (NSAttributedString *) already shouldn't they?
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
The objects will be NSAtteributedString objects so it will work, but the signature of objectAtIndex: is:

Code:
-(id) objectAtIndex:(int) index

so objects returned via this are id until you cast them.
 

rand0m3r

macrumors regular
Original poster
Jun 30, 2006
115
1
hey thanks it compiles now. but how come the text doesn't get drawn??!
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Post some of your code for the drawing. Is the NSPoint valid? Is it being drawn within a drawRect: method?
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Check if you are in a flipped view. Drawing text at (0,0) in a flipped view (or is it non-flippd I can never remember) draws the text outside the view as the co-ordinate system starts in the top left and text drawAtPoint: specifies the bottom left corner of the text bounding box so it draws off the top of the view...
 

rand0m3r

macrumors regular
Original poster
Jun 30, 2006
115
1
it is a flipped view but i thought it would be within the bounds.

NSAttributedString *testString;
testString = [[NSAttributedString alloc] initWithString:mad:"Testing"];
[(NSAttributedString *) testString drawAtPoint:NSMakePoint(100, 100)];

has it got anything to do with putting my view in focus?
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
How big is the view?
Where (in which method) is this code?
Why are you using an NSAttributedString without attributes? :p
 

rand0m3r

macrumors regular
Original poster
Jun 30, 2006
115
1
ah ok. i had NSBezierPath code in initFrame so i thought drawAtPoint would work there too.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.