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

Chirone

macrumors 6502
Original poster
Mar 2, 2009
279
0
NZ
it feels like i'm missing something

in the class that listens for an event i just did this:

Code:
NSNotificationCenter* nc;
		nc = [NSNotificationCenter defaultCenter];
		[nc addObserver: self
			   selector: @selector(handleViewChange:)
				   name: [Constants viewChangeNote]
				 object: nil];
where Constants is a custom class
so that makes the class listen for the notification

the method that posts the notification is like this:
printf("right\n");

NSMutableDictionary* info = [NSMutableDictionary dictionary];
[info setValue: [NSValue valueWithPoint: dragStartPoint] forKey: [Constants dragPointStart]];
[info setValue: [NSValue valueWithPoint: [event locationInWindow]] forKey: [Constants dragPointEnd]];

NSNotificationCenter* nc;
nc = [NSNotificationCenter defaultCenter];
[nc postNotificationName: [Constants viewChangeNote]
object: self
userInfo: info];
this happens when the user lets go of the right mouse button

now in the console "right" is printed out once
but straight after that the method that is assigned to that event (handleChangeView) happens twice
the statements that it prints out print out twice

right
handleViewChange before: 431.000000 390.000000 after 526.000000 393.000000
handleViewChange before: 431.000000 390.000000 after 526.000000 393.000000

any idea what i'm missing? :confused:
 
nevermind...

found the solution

i'm awakeFromNib is called twice, which meant it was being added as an observer to the same event twice, so i just had to put the adding observer code to the init method....
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.