views:

385

answers:

1

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

+2  A: 

[myView setNeedsDisplay] should cause drawRect: to be sent to myView the next time you're back in the run loop and myView is visible. If changing the bounds is causing the view to redraw (myView.contentMode is UIViewContentModeRedraw), then setNeedsDisplay 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.

Will Harris
Will,Ok this is weird. I had removed a call to [myView setNeedsDisplay] because it wasn't previously doing anything. I just put it back and drawRect is firing away. Sigh. Thanks for the assist.
dugla