【发布时间】:2011-07-07 11:39:53
【问题描述】:
我有一个自定义的 View 类,它是 UIView 的子类。
这个视图是通过 ViewController 中的一个 nib 文件加载的:
[[NSBundle main] loadNibNamed:@"MyCustomView" owner:self options:nil];
在 MyCustomView.h 内部(在 IB 中正确连接为 Main Views 类) 我链接了一些子视图属性:
@interface MyCustomView : UIView <UITextFieldDelegate> {
....
@public
UIView *backgroundLayer; // a subview of the Main View inside the nib
....
}
@property (nonatomic, retain) IBOutlet UIView *backgroundLayer;
此插座已在 Interface Builder 中正确连接。
在 MyCustomView.m 我有以下实现:
#import <quartzcore/QuartzCore.h>
@implementation MyCustomView
@synthesize backgroundLayer;
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
....
self.backgroundLayer.layer.cornerRadius = 12.0f;
self.backgroundLayer.layer.borderColor = [UIColor lightGrayColor].CGColor;
self.backgroundLayer.layer.maskToBounds = YES;
....
}
NONE 正在应用这些 backgroundLayer.layer 设置。当我在模拟器中运行时,自定义视图在没有任何这些模块的情况下完全显示在 NIB 中?我错过了什么?我是不是在错误的地方拨打电话?
【问题讨论】:
-
经过进一步检查,当我试图在 initWithCoder 中对其进行修改时,似乎 backgroundLayer 仍然为 NULL。
-
更新我们可以删除问题吗?刚刚发现-(void)awakeFromNib
标签: iphone cocoa-touch ios4 uiview interface-builder