I know how I'd do this with NSTextView, but NSTextField doesn't seem to provide a way to access the NSTextStorage
backing it, so I can't set myself as a delegate and process -textStorageDidProcessEditing:
.
I have a NSTextField
as part of a sheet. If that text field is emtpy at any point, the OK button should be disabled until some input is provided. That's basically all I'm looking to do, and I'm sure there's a really simple way to do this?
I tried:
[[[filenameInput cell] textStorage] setDelegate:self];
Thinking that NSTextFieldCell
would provide the text storage (mostly since Xcode kindly auto-completed it for me) and then of course, did my validation via the delegate method:
-(void)textStorageDidProcessEditing:(NSNotification *)notification {
BOOL allowSubmit = ([[filenameInput stringValue] length] > 0)
&& (([relativePathSwitch state] == NSOnState) || ([[localPathInput stringValue] length] > 0));
[createButton setEnabled:allowSubmit];
}
This compiles but causes a runtime error as NSTextFieldCell
does not respond to textStorage
.
What's the standard pattern I should be following here? This must be one of those "every day" tasks for Cocoa devs, I imagine :)