Re: NSNotifications
Re: NSNotifications
- Subject: Re: NSNotifications
- From: "Clint Shryock" <email@hidden>
- Date: Wed, 25 Oct 2006 20:48:34 -0500
couple of questions/thoughts.
first question:
static NSString *NSObjectDidChange;
does this ever get assigned a value somewhere? if not then you may be
posting a pointer that points to nothing...
something like NSObjectDidChange = @"MyObjectChanged"; would be needed.
even then i don't know where that string is declared so i can only assume
the receiving object knows what it is. i'll assume you have
done something similar.
next your notification seems off.
you send the notification from my3DObject, notification name
NSObjectDidChange with object type of my3DObject.
but in myViewClass you register them to listen for notifications with a name
of NSObjectDidChange and containing an object of mySuperModel, not
my3DObject. so i guess my3dObject is of type mySuperModel? if not this
could be a problem, or perhaps you just have a typo in your pseudo code.
if i wanted all views (myViewClass) to listen for a notification from
my3DObject when the mouse was dragged i would do:
my3DObject:
-(void)mouseDragged
{
.
.
.
[[NSNotificationCenter defaultCenter]
postNotificationName:@"CTSObjectDidChange" object: self];
.
.
.
}
myViewClass:
- (id)initWithFrame...
{
.
.
.
[[NSNotification defaultCenter] addObserver:self
selector:@selector(viewNeedsUpdate:)
name:@"CTSObjectDidChange"
object:nil];
.
.
.
}
doing it this way means my views don't care which object the notification
came from, just the name "CTSObjectDidChange".
i used CTS to start because those are my initials, i'm not sure about all
the rules for naming stuff with NS at the start, there are a few things
reserved for that.
the way you are posting below doesn't seem to match up. this could explain
why viewNeedsUpdate is not firing when you drag the mouse.
with out more code i can't really speculate as to why the views magically
fix them selves on mouse up.
I'm still learning cocoa so i may be completely wrong, maybe someone else
can help more.
anyway i hope i'm not and it helps you somewhere
-Clint
On 10/25/06, Aaron Boothello < email@hidden> wrote:
Hey Clint,
here's some pseudo code. and im currently only posting a notification
when i drag a mouse.....just testing to see if tis would actually work the
way i want it to.
my3DObject class: (poster of notification)
static NSString *NSObjectDidChange;
//called when object is changed to post a notification
-(void)objectDidChange
{
[[NSNotificationCenter defaultCenter]
postNotificationName:NSObjectDidChange object: self];
}
myView classes (each view is observer classes):
- (id)initWithFrame:(NSRect)frameRect
{
.
.
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(viewNeedsUpdate:)
name:NSObjectDidChange
object:mySuperModel];
.
.
}
- (void )mouseDragged:(NSEvent *)theEvent
{
// change object accoridingly
.
.
[myObject objectDidChange];
}
i'm not even posting a notification in the mouseUp method. but it only
seems to be refreshing the views when i life the mouse button (ive commented
out all the "[view setNeedsDisplay:YES]" in the code.
Out of curiosity i put a debugging statement in the "objectDidiChange"
method...a "printf"...and it just keep coming into this method no matter
what..weter or not the mouse is pressed or not.
Thanks.
_______________________________________________
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