开发者

How to make a .xib show up in a custom class

开发者 https://www.devze.com 2023-03-09 14:56 出处:网络
I was wondering how to connect my custom class and my .xib. In Interface Builder I have changed the class of the Files Owner to my custom class. I then created an IBOutlet and connected it to the view

I was wondering how to connect my custom class and my .xib. In Interface Builder I have changed the class of the Files Owner to my custom class. I then created an IBOutlet and connected it to the view of the .xib. I then added an instance of my custom class to my UIViewController. My custom class is a subclass of UIView, so I set the background of it to black and can see it appear on top of my UIViewController. What I can't see is my .xib???? Here is my code for my custom class... (FreeThrow is my custom class... FetView is my .xib)

@in开发者_C百科terface FreeThrow : UIView {
IBOutlet UIView *mySquareView;
}
@property(nonatomic, retain)IBOutlet UIView *mySquareView;
-(void)createMe;
@end


@implementation FreeThrow
@synthesize mySquareView;
-(void)createMe {
[self addSubview:mySquareView];
[self setBackgroundColor:[UIColor blackColor]]; // I did this to know my UIViewController is showing this class... which it is     
}
@end

Here is my code for what I call from my UIViewController...

freeThrowView = [[FreeThrow alloc] init];
[freeThrowView createMe];
freeThrowView.frame = CGRectMake(8, 42, 335, 230);
[self addSubview:freeThrowView];

What code do I need to add? What do I need to do? What is the problem? Why is my .xib not showing up.


Sadly apple doesn't give us a way to truly link a xib to a view via IB alone. You'll have to do it via instantiation. Here are some past answers to similar questions:

How do I associate a nib (.xib) file with a UIView?

Loading .xibs into a UIView

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号