我有兴趣编写我的自定义视图,所以我创建了以下 xib 文件:
这是定义文件:
- (void)_baseInit {
NSLog(@"Unseen View loaded");
[self addSubview:[self activityIndicator]];
[self activityIndicator].alpha = 1.0;
[self activityIndicator].frame = CGRectMake(round(([self imageView].frame.size.width - 25) / 2),
round(([self imageView].frame.size.height - 25) / 2), 25, 25);
[self activityIndicator].hidesWhenStopped = YES;
[self showIndicator];
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
[self imageView].userInteractionEnabled = YES;
[panRecognizer setMinimumNumberOfTouches:1];
[panRecognizer setMaximumNumberOfTouches:1];
[panRecognizer setDelegate:self];
[[self imageView] addGestureRecognizer:panRecognizer];
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self _baseInit];
}
return self;
}
- (id)initWithCoder:(NSCoder*)coder
{
if ((self = [super initWithCoder:coder])) {
[self _baseInit];
}
return self;
}
我试图将它连接到我的故事板中:
我让我的 MainViewController 在 viewDidLoad 期间调用它:
- (void)viewDidLoad {
[super viewDidLoad];
self.unseenView = [[[NSBundle mainBundle] loadNibNamed:@"UnseenView" owner:self options:nil] objectAtIndex:0];
self.unseenView.delegate = self;
不幸的是,我的模拟器中什么也没有显示,甚至文本标签也没有。
但是我看到以下日志消息:
2013-02-20 17:37:58.929 Giordano.iPhone[66857:c07] Unseen View loaded
2013-02-20 17:37:58.934 Giordano.iPhone[66857:c07] Unseen View loaded
我究竟做错了什么?