我有一个BasicView:
#import "BasicView.h"
@implementation BasicView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
+(instancetype)initializeFromNib:(NSString*)nibName {
return (BasicView*)[[[NSBundle mainBundle] loadNibNamed:nibName owner:self options:0] objectAtIndex:0];
}
继承自它的观点:
@interface AlbumPicturesView : BasicView
/**
The pictures label - need be removed once there are pictures in the album
*/
@property (weak, nonatomic) IBOutlet UILabel *picturesLabel;
/**
The pictures cell view
*/
@property (weak, nonatomic) IBOutlet UICollectionView *picturesCollectionView;
@end
#import "AlbumPicturesView.h"
@implementation AlbumPicturesView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end
使用xib文件。
我尝试使用以下功能在屏幕上显示此视图:
/**
Show the pictures view view on the right position on the screen
*/
-(void) showPicturesView {
_albumPicturesView = [AlbumPicturesView initializeFromNib:VIEW_ALBUM_PICTURES];
[self.view addSubview:_albumPicturesView];
float yPosition = _albumIconsView.frame.origin.y + _albumIconsView.frame.size.height;
float height = self.view.frame.size.height - yPosition;
_albumPicturesView.frame = CGRectMake(_albumPicturesView.frame.origin.x, yPosition, _albumPicturesView.frame.size.width, height);
}
但我一直得到:
[<AlbumPicturesView 0x113104> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key picturesCollectionView.
虽然这一切都在界面构建器中设置..有人可以解释一下原因吗?
答案 0 :(得分:1)
您可能在IB中有一个连接到picturesCollectionView的插座。现在你的课程中不再存在该插座(或者它是不正确的课程类型)。你也需要在IB中删除它。
另一种可能性,您已选择BasicView
作为xib中的类而不是AlbumPicturesView
。