I have this code in my NSButton
subclass:
-(void)mouseEntered:(NSEvent *)theEvent{
NSLog(@"ENTER");
NSString *myString = @"foo";
[myTextField setStringValue:myString];
}
-(IBAction)changeStringValue:(id)sender{
NSString *myString = @"foo";
[myTextField setStringValue:myString];
}
The IBAction works fine but the same method of myTextField
called inside the mouseEntered event
doesn't work. The event is working (except setString), in fact I can see the NSLog and if I insert NSLog(@"%@", myTextField.stringValue);
, it says null
.
Does anyone have a clue?
Edit: I noticed that the previous stringValue NSLog, if inserted in -(void)awakeFromNib{...}
, occours 2 times even if there's only one button of MyButton
class: one time it's correct and the other time it's null
. I'm a little bit confused.
Edit2: i've inserted [self performSelectorOnMainThread:@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.