Skip navigation.
 
mlRe: NSTextView and Click on Button
FROM : Joshua Emmons
DATE : Wed Nov 28 22:49:23 2007

> I know there is a ton of documentation on this but if you don't know 
> how to ask the right question you will never find the right 
> answer...  I have tried but I just can't seem to find what I'm 
> looking for.



The question you want to ask has to do with First Responder, so I 
would recommend reading up on that. In addition to being a generally 
fascinating topic, being knowledgeable in it will pay great dividends 
when debugging obscure behavior in the future.

http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals/CoreAppArchitecture/chapter_7_section_6.html
http://developer.apple.com/documentation/Cocoa/Conceptual/EventOverview/index.html

Also of general responder interest (though maybe not to you if you're 
using NSTextViews?) is the field editors. It inserts itself into the 
responder chain and causes general confusion to new users of the cocoa 
text system. I don't think NSTextViews, being full-blown "heavy" text 
objects in and of themselves, use a field editor... but again, it's 
something worth knowing.

http://developer.apple.com/documentation/Cocoa/Conceptual/TextArchitecture/Concepts/TextFieldsAndViews.html
http://developer.apple.com/documentation/Cocoa/Conceptual/TextEditing/Tasks/FieldEditor.html

> On the button click I'd like to do something like:
> [myTextView textShouldEndEditing]  but that doesn't work.


I believe you'll want to call [yourWindow makeFirstResponder:nil];

http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindow_Class/Reference/Reference.html#/
/apple_ref/occ/instm/NSWindow/makeFirstResponder:

This will send a -resignFirstResponder to the current first responder 
(in this case, your text view) causing it to commit its changes. After 
that, the value should be what you expect it to be.

Cheers!
-Joshua Emmons

Related mailsAuthorDate
mlNSTextView and Click on Button Steve Cronin Nov 28, 21:53
mlRe: NSTextView and Click on Button Joshua Emmons Nov 28, 22:49
mlRe: NSTextView and Click on Button Steve Cronin Nov 29, 04:04