简体   繁体   中英

Custom NSCell drawWithFrame:inView method not getting invoked in OSX 10.8

I have an application where I have defined a custom cell and have overridden the method - (void) drawWithFrame:inView:

This method was drawing my custom cells without any problems as long as I was building my app using Xcode 3.2 on OS X 10.6 or older.

Now I am attempting to migrate the code to build with Xcode 4+ on OS X 10.8. And what I have found out is that my custom cell is not getting drawn anymore. After putting break points and running the app through the debugger, I realized that the overridden - (void) drawWithFrame:inView: method of the custom cell is not getting invoked at all.

My questions are:

1) What is it that makes this method to not invoke at all on OS X 10.8, while it gets invoked and works perfectly fine on OS X 10.6 or older?

2) What alternative do I have to fix this issue?

Thanks, Mriganka

I am having the same problem, except i am using xcode 4.x on OSX 10.7

Maybe its an xcode 4.x thing?

What I have noticed is that drawWithFrame on my subclassed NSTextFieldCell does NOT get invoked when i call setEnabled (changing from YES to NO or NO to YES) on the parent NSTextField, after initialization of my NSTextFieldCell, but before drawWithFrame on that NSCell gets invoked automatically.

However, if I call setEnabled (after initializing my subclassed NSTextFieldCell) and no change occurs (ie. setEnabled:YES but it is already set to YES), then drawWithFrame does indeed get invoked.

Unfortunately, i need to perform setEnabled from YES to NO to YES, as i want to disable my NSTextField while a server call is being made, and then enable it on the callback. If the callback is (for example 'wrong password'), i need to custom draw the NSTextFieldCell border red.. and I have to do this by overriding drawWithFrame.

My guess is that setEnabled utilizes NSGraphicsContext and does a savesGraphicsState/restoreGraphicsState (perhaps in error), which throws off the graphics context that is utilized in NSTextFieldCell/drawWithFrame.

My guess is that the NSGraphicsContext within setEnabled is ONLY utilized if a change occurs (setEnabled from YES to NO or NO to YES), since when a change DOES NOT occur, I have no issue… I think this would make sense as there would be no point in rendering new graphics to show the user that the view is not selectable or editable, because it does indeed ALREADY LOOK not selectable or editable.

The answer to my problem was to re-draw manually after i called setEnabled, by calling setNeedsDisplay on the NSTextField.

I think this will probably work for you as well, as it causes the draw to occur manually.

glhf!

-Eric

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM