I haven't extended a UI object, so take this all with a grain of salt.Originally Posted by Jirka Jirout
The first thing I see if that you are using the -display from NSView method rather than -setNeedsDisplay from NSControl. The first forces the display, while the second just marks it as needing the display and lets the run loop handle updating it when it gets around it to. All the examples I have seen use the later approach.
The second thing is that (at a quick glance) I wonder if you really need a sub-class of the object. Why not just make a delegate object that listens for the NSControlTextDidChangeNotification notification and then update your position accordingly?
The only thing that jumps out at me is how you handle attrString. You are not initializing it anywhere, so your -autorelease call on it (should be -release rather than -autorelease anyway) in -setStringValue is going to have unknown results. Secondly when you are creating the string later, you are not issuing a -retain call on it which means it goes out of scope (and see the previous issue).
I would suggest that you:
1) Add an -init method to (at a minimum) set all your class variable to nil (or 0).
2) Test for attrString to not be nil before you try to release it.
3) Add a retain call when you create attrString so that it is available to all your methods and is carried over from call to call (if that is indeed it's purpose as it appears).
Finally, I have spent many hours debugging what I thought was the problem (based the debugger) only to find that it was actually an entirely different object causing the issue. If none of the above helps, i'd try throwing NSLog's every where to figure out exactly where it is crashing (my case was a completly unrelated object being nil when I tried to reference it, but the debugger had me looking at something else ).
Hope some of that helps,