【发布时间】:2017-10-01 06:47:18
【问题描述】:
我有一个自定义的UIView,我正在以这种方式加载它
- (id)initWithFrame:(CGRect)frame withDelegate:(id)del
{
self = [super initWithFrame:frame];
UIView *myView;
if (self)
{
NSArray* nibViews = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class])
owner:self
options:nil];
for (id object in nibViews)
{
if ([object isKindOfClass:[self class]])
myView = object;
}
myView.frame = frame;
myView.backgroundColor = [UIColor clearColor];
[self addSubview: myView];
}
self.delegate = del;
return self;
}
当 UIView 方法返回 self 时,像这样加载视图时,Interface Builder 中链接的所有出口都是 nil。这不是正确的方法吗?
【问题讨论】:
-
你不需要
for-loop只需使用myView = [nibViews firstObject]; -
如果可能,请分享演示代码。
标签: ios objective-c iphone uiview xib