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: se llama).
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.
¿Por qué es
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 resulta en un
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.
preguntado el 09 de enero de 11 a las 10:01
I just ran into the same problem myself. For me it was an issue with my XIB - I am subclassing a UIView though - so adapt accordingly. My mistake in IB was that I attached my controls to the "file's owner" instead of attaching them to the UIView. I'm sure that in my inexperience there is something larger going on - perhaps someone with a bit more experience can elaborate.
Espero que ayude!