Cocoa-Matic

iPhone, iPod touch, iPad tutorials, examples and sample code. Come and get it!

Friday, July 30, 2010

Creating UIViews programmatically

If you want to create a new UIViewController object without using a Nib file in Interface Builder, you must use the loadView method. It's rather simple, but key to doing things programmatically.
- (void)loadView {
 CGRect viewFrame;
 viewFrame = CGRectMake(0, 0, MASTER_WIDTH, MASTER_HEIGHT);
 self.view = [[[UIView alloc] initWithFrame:viewFrame] autorelease];
}
(Note: MASTER_WIDTH and MASTER_HEIGHT are simply constants defining the width and height of the screen.)

Once your view is created, you are free to implement, as usual, viewDidLoad, viewWillAppear, viewDidAppear, etc.

Labels: , , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]



<< Home


« Older Entries  
Newer Entries »