Skip navigation.
 
mlRe: Programatically accepting NSTextField content
FROM : Christiaan Hofman
DATE : Fri Mar 28 23:04:36 2008

On 28 Mar 2008, at 7:41 PM, Steve Nicholson wrote:

> On Mar 28, 2008, at 11:30 AM, Christiaan Hofman wrote:

>>
>> On 28 Mar 2008, at 7:19 PM, Steve Nicholson wrote:

>>> On Mar 28, 2008, at 10:44 AM, Christiaan Hofman wrote:

>>>> There are 2 ways I know of.
>>>>
>>>> 1. Change the first responder of your window, to force edits to 
>>>> be committed.

>>>
>>> I put this in the beginning of the method that handles the button 
>>> click and it did the trick:
>>>
>>>     if ([[self window] firstResponder] == [zoneText currentEditor])
>>>     {
>>>         [zoneText resignFirstResponder];
>>>         [zoneText becomeFirstResponder];
>>>     }
>>>
>>> Thanks, Christian. I really appreciate your help.
>>>
>>> -Steve

>>
>> Those are the wrong methods to call though. The docs on 
>> becomeFirstResponder and resignFirstResponder say:
>>
>> Use the NSWindow makeFirstResponder: method, not this method, to 
>> make an object the first responder. Never invoke this method 
>> directly.
>>
>> Christiaan
>>

> I think I can justify calling them directly since, technically, I'm 
> not changing the first responder. I'm simply jostling it. :-) I 
> don't want to change the first responder since the user didn't 
> initiate the change.


That doesn't matter.

> My feeling is that we aren't supposed to invoke those methods 
> directly since doing it incorrectly might create zero or two first 
> responders.



or the view thinking it's thinking it's first responder while the 
window thinks otherwise. You just don't know. Also, is the field 
editor removed and added correctly? You don't know.

> I'm going to go ahead and risk it. Anyway, this is an in-house app 
> which is pretty much only being used by me and one other guy so if 
> something weird happens It'll only affect us.


Of course, it's your own risk. But you should never do this in a 
shipping app. If the docs say you shouldn't do it, there usually is a 
reason for it.

Christiaan

Related mailsAuthorDate
mlProgramatically accepting NSTextField content Steve Nicholson Mar 28, 17:45
mlRe: Programatically accepting NSTextField content Christiaan Hofman Mar 28, 18:44
mlRe: Programatically accepting NSTextField content Steve Nicholson Mar 28, 19:19
mlRe: Programatically accepting NSTextField content Christiaan Hofman Mar 28, 19:30
mlRe: Programatically accepting NSTextField content Steve Nicholson Mar 28, 19:41
mlRe: Programatically accepting NSTextField content Christiaan Hofman Mar 28, 23:04