Redrawing Views

When a UIView instance receives the message setNeedsDisplay, it will redraw its image. View subclasses send themselves setNeedsDisplay when their drawable content changes. For example, a UILabel will mark itself for re-display if it is sent the message setText:. (It has to redraw its image if the text it displays changes.)

The redrawing of a view’s image is not immediate; instead, it is added to a list of views that need updating. To understand when views actually get redrawn, we need to talk about the run loop – the infinite loop that comprises an iOS application. The run loop’s job is to listen for input (a touch, Core Location updates, data coming in through a network interface, etc.) and then find the appropriate handlers ...

Get iOS Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.