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

Val K

macrumors member
Original poster
Dec 19, 2012
33
0
Italy
Hi, i have this code in MyButton.m, subclass of NSButton.

Code:
-(void)updateTrackingAreas{
	if (trackingArea){
		[self removeTrackingArea:trackingArea];
	}
	NSTrackingAreaOptions options = NSTrackingInVisibleRect | NSTrackingMouseEnteredAndExited | NSTrackingActiveInKeyWindow;
	trackingArea = [[NSTrackingArea alloc] initWithRect:NSZeroRect options:options owner:self userInfo:nil];
	[self addTrackingArea:trackingArea];
}
-(void)mouseEntered:(NSEvent *)theEvent{
	NSLog(@"ENTER");
	[myTextField setStringValue:@"Foo"];
	NSLog(@"label: %@", myTextField.stringValue);
}
-(IBAction)changeStringValue:(id)sender{
	[myTextField setStringValue:@"Foo"];
}

If i call the changeStringValue IBAction everything goes fine, but nothing happens hovering the NSButton associated with the MyButton class, it only shows the NSLog "ENTER" message but myTextField stringvalue isn't updated and the "label:" nslog says NULL.
Does anyone have a clue?

Edit:
I've inserted [self performSelectorOnMainThread:mad:selector(changeStringValue: ) withObject:myTextField waitUntilDone:YES]; inside the mouseEnter: event and NSLog(@"Running"); inside the changeStringValue function: now hovering the button i call the function (i see the "running" log) but nothing happens. The function, as a Sent Action assigned to a button, is still working. I've also tried with waitUntilDone:YES/NO and withObject:myTextField/self but it's the same.
 
Last edited:
solved

nevermind, i solved the problem using NSNotificationCenter. Apparently there's no alternative to it.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.