Technical Q&A QA1461

Disabling and Enabling an NSTextView

Q:  How do I disable and enable an NSTextView?

A: How do I disable and enable an NSTextView?

Currently there is no direct way to disable and re-enable an NSTextView. However, with a few lines of code you can implement this feature on your own. The sample code below best illustrates this by changing the selectable and editable attributes as well as its text color.

Listing 1  Disabling and Enabling NSTextView

-(void)enableTextView:(BOOL)enableIt
{
        [textView setSelectable: enableIt];
        [textView setEditable: enableIt];
        if (enableIt)
                [textView setTextColor: [NSColor controlTextColor]];
        else
                [textView setTextColor: [NSColor disabledControlTextColor]];
}


Document Revision History


DateNotes
2006-09-11

New document that shows how a Cocoa application can disable and enable an NSTextView.