I am doing a scientific visualization app for iPhone. Periodically a UIView subclass will receive some data from the network that it must render via its overridden drawRect: method.
My challenge is that there is no way to indicate to Cocoa-Touch that this data has arrived – or changed – other then [myView setNeedsDisplay] which is ignored except for changes to the bounds of the UIView. I have tried hiding and unhiding. Nuthin'.
Maddeningly, since all I did was alter some internal state of the UIView [myView setNeedsDisplay]. This change is completely invisible to Cocoa-Touch. This change is not one of the criteria that warrents a redraw – according to Cocoa-Touch – thus my UIView sits there, unchanged.
This is very, very, very frustrating. I have hit a wall here.
Could someone please suggest a technique, a trick, a hack, that will prompt my UIView to re-render.
Cheers,
Doug
Best Answer
[myView setNeedsDisplay]
should causedrawRect:
to be sent tomyView
the next time you're back in the run loop andmyView
is visible. If changing the bounds is causing the view to redraw (myView.contentMode
isUIViewContentModeRedraw
), thensetNeedsDisplay
must be working, since that's how the redraw is signalled by the bounds change. See the UIView class reference for details.Is your
drawRect:
being invoked the first time the view is shown? If not, it may be misspelled, overridden in a subclass, or even on the wrong object.Is the view visible and on screen? It won't be drawn if it is off screen.
Is control returning to the event loop?
drawRect:
won't be invoked if your application is busy.