【发布时间】:2016-02-01 19:21:42
【问题描述】:
我有以下文件:
- ViewController.xib
- ViewController.h
- ViewController.m
- BannerView.xib
- BannerView.h(继承自 UIView)
- BannerView.m
我的视图控制器已连接并且工作正常。我创建了 BannerView 并按照本教程中的说明执行了必要的链接:http://www.maytro.com/2014/04/27/building-reusable-views-with-interface-builder-and-auto-layout.html
但是,在我的 ViewController.xib 中,当我添加 UIView 并将其类设置为 BannerView 时,它不会加载。该应用程序不会崩溃或发生任何事情。
我是否遗漏了任何步骤,我们将不胜感激。
编辑 1 - 添加图像和代码
BannerView.h
@property (nonatomic, strong) IBOutlet UIView *view;
#import "BannerView.h"
@implementation BannerView
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if(self) {
[self setup];
}
return self;
}
- (void)setup {
[[NSBundle mainBundle] loadNibNamed:@"BannerView" owner:self options:nil];
[self addSubview:self.view];
}
@end
横幅视图 XIB - 文件所有者
横幅视图 - 视图
【问题讨论】:
-
您能否显示“添加 UIView 并将其类设置为它只是不加载的 BannerView”的代码?
标签: ios objective-c interface-builder xib