I have a custom UIView which is a sub-view of a UITableViewCell. When the cell is drawn, so is my custom view, correctly calling drawRect: in my UIView sub-class. When the cell is reloaded, the view is drawn correctly (drawRect:
is called).
When a certain event happens (eg timer), I want to redraw the view without having to reload the whole cell. (This is not the only view in the cell.)
However, when I call setNeedsDisplay
on my sub-view, nothing happens.
I'm guessing that when my view's drawRect:
is called, the resulting image is cached in a backing somewhere such that when I call setNeedsDisplay
that backing is redrawn to the screen, but my drawRect:
call is never called again.
Why is drawRect:
never called again after the cell is created?
EDIT: The cell's subviews are created from from a nib. ie: a UIViewController is loaded from the nib and its view is added to the UITableViewCell.
I made a test case from scratch with a custom view that isn't loaded from a nib (created by code) and it works as expected: setNeedsDisplay
results in a drawRect:
call. It must be something that's either set up in the .xib file or something that happens differently to a view when it's loaded from a nib.