該教程的作者使用視圖出口從XIB加載視圖時MYBannerView
被編程初始化在界面生成器創建
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
NSString *className = NSStringFromClass([self class]);
self.view = [[[NSBundle mainBundle] loadNibNamed:className owner:self options:nil] firstObject];
[self addSubview:self.view];
return self;
}
return nil;
}
任何不會與程序上init
被加載。 loadNibNamed
從xib加載用戶界面。
如果你想覆蓋initWithFrame:
加載從廈門國際銀行的UI元素,您的init方法看起來是這樣的:
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame]; // initialize your objects
if (self) {
[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:self options:nil]; // load your view from IB
}
return self; // return the view with all of the IB UI loaded
}
來源
2015-11-05 19:56:36
JAL
理論上你不需要的屬性,可以使用自... – kikko088
它爲什麼需要它?你在哪裏讀到的? –
我添加了我用作教程的原始鏈接 – user1686342