1) In Interface Builder, change the class name of your View object to MyView.

2) Then you will have to override MyView's initWithFrame method like so:
- (id)initWithFrame:(CGRect)paramFrame
{
NSArray *arrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"MyView"
owner:nil
options:nil];
if ([arrayOfViews count] < 1){
[self release];
return nil;
}
MyView *newView = [[arrayOfViews objectAtIndex:0] retain];
[newView setFrame:paramFrame];
[self release];
self = newView;
return self;
}Then you can go ahead and initialize your view like this:
MyView *myView = [[MyView alloc] initWithFrame:self.view.bounds]; [self.view addSubview:myView]; [myView release];
And here an instance of MyView will get added to the view of a view controller. That simple. I hope it helps some of you out there :-)
You can build a variety of amazing apps on the iOS platform—and every one of them presents a unique set of problems. With the recipes in this cookbook, you'll go beyond theory to solve the vexing, real-life issues you’re likely to face when creating apps for the iPhone, iPad, or iPod Touch. Complete with solutions for problems faced by beginning, intermediate, and advanced developers, this book will take you from concept all the way to the App Store.




Help





