I am trying to create a custom UIView and have it load in a xib file. The custom UIView is called JtView and here is the code:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
NSLog(@"initWithFrame was called"); // this was called
if (self) {
// Initialization code
[[NSBundle mainBundle] loadNibNamed:@"MyView" owner:self options:NULL];
[self addSubview:self.view];
}
return self;
}
-(void)awakeFromNib
{
[super awakeFromNib];
[self addSubview:self.view];
}
In creating the xib file (File -> New -> File -> User Interface -> View), I deleted out the main Window and dragged a View from Xcode's object pallette. I tried alt-dragging to the header for JtView but this wasn't working. Do I need to create an association here or should I just leave what XCode created in place? (edit - see comments below for further clarification)
I have also added a UILabel to the xib.
However, when I run in simulator and set the background color to red, the label is not showing up. Do I need to create the UILabel as a reference in the custom UIView? Should I be deleting this or leaving it in place?
thx
edit 1 Here's a screenshot of the connections and the header file:
Window
. I've hooked up the file's owner to the View but the label is still not showing up. – timpone