I’m stuck on how to get the Send button enabled once some text has been entered into the message field. I’ve created the IsNotEmptyTransformer class:
[code]import Cocoa
class IsNotEmptyTransformer: NSValueTransformer {
class func transformedValueClass(value: AnyObject?) -> AnyObject? {
return IsNotEmptyTransformer.self
}
class override func allowsReverseTransformation () -> Bool {
return false
}
class func transformedValue(value: AnyObject?) -> AnyObject? {
return !(value!.message == "")
}
}
[/code]
I’ve registered the transformer in the AppDelegate:
[code] dynamic var isNotEmptyTransformer = IsNotEmptyTransformer()
func applicationDidFinishLaunching(aNotification: NSNotification) {
// Insert code here to initialize your application
NSValueTransformer.setValueTransformer(isNotEmptyTransformer, forName: "IsNotEmptyTransformer")
addWindowController()
}
[/code]
And, I’ve set the Send button’s Value binding to message in the Model Key Path and in the ValueTransformer I’ve set the IsNotEmptyTransformer class. I also set the message text field’s Continuously Updates Value on.
When I run the program, the Send button is always disabled. Entering text into the message text field does not change the button’s enabled state. I’ve also set breakpoints on all the IsNotEmptyTransformer’s methods and none of them is ever being called. I’ve verified in the debugger that the IsNotEmptyTransformer has in fact been registered. I’m at a dead end, I don’t understand why the transformer’s methods are not being called. What am I missing that is preventing the button from becoming enabled with the text entry?
Thanks,
Brian