Thursday, April 30, 2009

The UIView class and the View XIB

One of the harder concepts to absorb when first learning the iPhone SDK is the "directionality" and control flow of UIView objects and UIViewController objects. Both can be created using the Interface Builder and both can be created entirely from code. I can't possibly go into all of that right now, but let's just say that if you stick to one technique or another, you'll "get it" pretty quickly but you won't be able to solve all the problems that arise.

One such problem is when you need to programmatically change a View (such as, refreshing 2D graphics using Quartz) but you also want a XIB for that view, making it easier to embed standard controls. I found a great answer to this question at this Web site.

In short, you create both a custom View (derived from UIView) then you point the XIB's View's Identity to that custom class. When you refresh graphics using drawRect(), it refreshes right onto the View you created with Interface Builder. Refer to the above link for code samples.

No comments:

Post a Comment