【发布时间】:2011-02-15 16:29:39
【问题描述】:
我创建了一个从 nib 加载其内容的自定义视图,如下所示:
/* PricingDataView.h */
#import <UIKit/UIKIt.h>
@interface PricingDataView : UIView {
UIView *contentView;
}
@property (nonatomic, retain) IBOutlet UIView *contentView;
@end
/* PricingDataView.m */
#import "PricingDataView.h"
@implementation PricingDataView
@synthesize contentView;
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
[[NSBundle mainBundle] loadNibNamed:@"PricingDataView" owner:self options:nil];
[contentView setFrame:frame];
[self addSubview:contentView];
}
return self;
}
/* ... */
在 nib 文件中我将PricingDataView 设置为文件所有者的类型,并在 IB 中连接了contentView 出口。我将接口库中的常规UIView 放置到向用户显示的全尺寸视图上,然后将其类名更改为PricingDataView。这一切都在构建,但在运行时,我的自定义视图应该在的位置没有呈现任何内容。
我在PricingDataView.initWithFrame 中设置了断点,但它们没有命中,所以我知道我遗漏了一些会导致视图被初始化的东西。我很好奇的是,在从笔尖加载我的其他视图的过程中,所有的初始化都发生在我身上,但不是这个。为什么?
【问题讨论】:
标签: iphone objective-c interface-builder views nib