Re: custom NSView problem
Re: custom NSView problem
- Subject: Re: custom NSView problem
- From: Matt Neuburg <email@hidden>
- Date: Tue, 14 Sep 2004 11:20:03 -0700
On Sun, 12 Sep 2004 10:29:29 -0700, Matt Neuburg <email@hidden> said:
>On Sat, 11 Sep 2004 13:17:31 +0100, Peter Browne
><email@hidden> said:
>>Hi,
>>I have a custom NSView, (named targetView) and when the user clicks on
>>the window, I want the coordinates of the click to be displayed in an
>>NSTextField. Everything works fine, except when mouseDown: is called,
>>the NSTextField isn't updated. I don't get any errors, simply nothing
>>happens.
>>
>>This is what I have written so far. 'center' is the NSPoint initially
>>at the center of the window until there is a mouse click, 'currtgt' is
>>the outlet name for the NSTextField, and 'tgt' is an NSString. Any
>>ideas?
>>
>>- (void)mouseDown:(NSEvent *)event
>>{
>>
>> NSPoint eventLocation = [event locationInWindow];
>> center = [self convertPoint:eventLocation fromView:nil];
>> [self setNeedsDisplay:YES];
>>
>> NSLog(@"New target designated at coordinates: (%.0f,%.0f)",
>>center.x, center.y);
>>
>> tgt = NSStringFromPoint(center);
>> [currtgt setStringValue:tgt];
>>}
>
>If it all works just fine up to and including the NSLog, but then the
>NSTextField does not change, I would have to suggest that, no, currtgt is
>*not* the outlet name for the NSTextField - it is a name for nil. Messages
>to nil don't generate any error message, but they don't do anything either.
>Check your names and your IB outlets
Just for the record, the O.P. told me offline that he proceeded to add an
NSLog message to check this, and sure enough his currtgt outlet *was* nil.
But he didn't know why, and neither do I. I sent him a small example app
that does what his app is trying to do (set an NSTextField with a string
version of the location of the click in an NSView subclass, via an outlet
from the NSView to the NSTextField). My example works fine. I have not heard
back as to what, if anything, he learned about what was going wrong with his
app. m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide
<http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt>
_______________________________________________
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