0

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.

Val K.
  • 113
  • 1
  • 10
  • answers even disappear :D If I bind the subclass `MyButton` into AppDelegate and insert `-(void)awakeFromNib{NSLog(@"awake: %@", myButton.myTextField.stringValue);}` in `AppDelegate.m`, it displays the right value too. Why is it `null` in mouseEntered? – Val K. Jun 18 '13 at 09:07
  • SOLVED. I used NSNotificationCenter and it seems to be no alternative to it. – Val K. Jun 19 '13 at 08:40

0 Answers0