2
votes

I've subclassed and defined my own custom NSFormatter and NSTextField classes in order properly display SMPTE time code values (HH:MM:SS:FF). When the user selects to use drop-frame for the fps value, the format changes to HH:MM:SS;FF (semi-colon at the end). I have this all working well except for one final hurdle.

When changing the format, the NSTextField with the focus does not update it's display until it's focus is lost. Here is a screenshot to illustrate:

Changing to drop-frame format

I have tried sending the NSTextField a setNeedsDisplay message when the format is changed, as well as sending it a display message. Nothing seems to work so far, and the text field with focus refuses to update/redraw itself until it loses focus.

Any suggestions of what I need to do to make this happen?

1
I thought it may have something to do with that. I've been trying for the past few hours though, and I still can't seem to get it to work. I can get the NSTextFieldCell object but from there I can't seem to access the field editor. Sending the fieldEditorForView: or fieldEditor:forObject: gives me a "does not respond to selector" error. Furthermore, I've tried the drawWithFrame:inView: for the NSTextFieldCell, and no dice. setNeedsDisplayInRect:avoidAdditionalLayout: looks promising, but I can't get to the NSTextView instance of my text box.Chris
Would data binding be what you are after? In that case you need to look at this Key-Value Observing manual. It will at least give you the right terms to search for. developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/…timquinn
@Monolo No, I sent it to the cell. I know it is an NSWindow method, but it showed up as a possible message to the cell receiver, so I gave it a shot. :)Chris
@Chris I see you found a solution - we can clean up all these comments here, then :-)Monolo

1 Answers

1
votes

I did manage to solve this problem now. It may be a bit of a hack, but basically what I ended up doing was retrieving the NSTextField's field editor with currentEditor and sending it as an object with the posted notification for when the format changes.

With the field editor I then just had it replaceCharactersInRange:withString: to change the last ":" to ";" and vice-versa. Though it may not be optimal, it works perfectly.

In fact, I've posted the solution to github for anyone else who might find this useful. https://github.com/cfloisand/smpteformatter