Updating a cell in NSTableView - it just will not draw!
Updating a cell in NSTableView - it just will not draw!
- Subject: Updating a cell in NSTableView - it just will not draw!
- From: Graham Cox <email@hidden>
- Date: Mon, 21 Apr 2008 14:33:30 +1000
This is a weird one, I've been battling this for many hours now with
no luck, so I hope the list can help.
I have a NSTableView in which I am drawing a custom cell. The custom
cell draws fine when the table is loaded and used normally - (BTW, the
custom cell just draws a colour swatch).
When the cell is clicked, I pop up a "menu" which has an array of
colours and this allows me to quickly pick a colour for the cell. This
"menu" is actually a fairly complex bit of code that creates a
borderless window, stuffs a view into it and does a whole load of
event tracking within its own tracking loop to track the mouse,
highlight the colour under the mouse, send it to its target/action and
so on. I've used this code in a couple of projects without any
problems - usually when the target/action receives the colour change
from the menu it posts a setNeedsDisplay: which then redraws the
colour as the menu is tracked. So I'm pretty sure that as such this
class works OK, at least when interacting with views that aren't doing
anything tricky.
The problem I'm having is that when the menu is used to update the
cell in the table view, I just cannot get the darn thing to redraw. At
all. (at least until after the menu tracking returns and it goes
away). I've tried:
1. [table updateCell:self];
2. [table setNeedsDisplay:YES];
3. [table lockFocus];
[self drawInteriorWithFrame:myFrame inView:table];
[table unlockFocus];
In no case can I get "live" updates of the cell. I've checked that I
have a valid table, valid frame, valid everything - all looks fine.
Ultimately this is being called from a tracking event loop within the
menu code, which in turn is called from the original mouseDown: method
of the table - so the call stack is somewhat wound up, but even so, it
should work, shouldn't it? The menu's tracking loop calls [window
nextEventMatchingMask:] and "window" is obviously the popped up "menu"
window. This shouldn't block updates in other windows/views though,
should it? I mean, I've not hit this problem before using the same
code. Should I be doing something in my tracking loop to ensure
updates for other windows are processed? I've not previously found the
need to.
Is it possible that NSTableView is doing something weird with the
graphics state (for optimisation purposes, perhaps?) or have I just
missed something really obvious? I realise it's hard to answer without
seeing all this custom code that is probably where the problem lies,
but as I said, it works fine with any other view I've used it with -
just not with tables.
------
S.O.S.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden