views:

74

answers:

1

I have a small gui app that consists selectable groups, each groups has a disclosure button to display its sub-group, an image and a text field. When you are editting a text field and select another group or another text field I want to end editting on the old text field. Also, I only want the background of a text field to be display when it is being editted.

I am trying to accomplish this by adding a call to activate the background in becomeFirstResponder and deactivate in textDidEndEditting. I ended up putting the call to deactivate in textDidEndEditting instead of resignFirstResponder because it seems that when I select the textField it calls resignFirstResponder right after becomeFirstResponder. I am wondering is this normal behavior or is this a sign of some other problem with my code? If this is normal behavior is there a better place to put the call to deactivate that background because having it in textDidEndEditting in problematic.

A: 

I don't think the same text field is calling both resignFirstResponder and becomeFirstResponder.

Text fields should automatically end editing when you move the focus to another UI element. You shouldn't have to manually manage that. However, if you want to alter a field upon it gaining or losing focus, you should put that functionality in becomeFirstResponder and resignFirstResponder respectively.

TechZen
@TechZen I don't think I was quite clear enough in what I am trying to do. I want the text field to only display its background when it is being edited so when it is no longer being edited I need to call SetBackground NOAlso, after further research I have read that when the NSTextField becomes first responder it hands over firstresponder status to its NSTextView and this is why it resigns firstresponder right away. http://www.cocoabuilder.com/archive/cocoa/60673-becomefirstresponder-and-resignfirstresponder.html
Mike2012
I don't want to override NSTextView's becomesFirstResponder because this will cause issues for any other methods that might use an NSTextView and it would not be able to set the background anyway. Is there no other callback that would be suitable for this?
Mike2012