所以我有一个名为 CSImageViews 的类(uiview 的子类),它本质上是包含在单个子类 UIView 中的一行 UIImageViews。
我已经像这样添加了一个自定义初始化方法(节点/yaml 包含 uiimage 名称数据):
- (id)initWithFrame:(CGRect)frame withNode:(NSDictionary *)node
{
self = [super initWithFrame:frame];
if (self) {
_node = node;
_imageViewYAML = [node objectForKey:@"items"];
_imageViews = [self getImageViewsForItems:_imageViewYAML];
}
return self;
}
我的 getImageViewsforItems 就是这样(将它们全部添加到子视图中):
-(NSArray *)getImageViewsForItems:(NSArray *)items
{
NSMutableArray *ivs = [NSMutableArray arrayWithCapacity:[items count]];
for (int i = 0; i < [items count]; i++) {
NSDictionary *item = [items objectAtIndex:i];
NSString *type = [item objectForKey:@"type"];
NSString *name = [item objectForKey:@"name"];
UIImage *image = [UIImage imageNamed:name];
UIImageView *iv = [[UIImageView alloc] init];
iv.image = image;
iv.tag = i;
[ivs addObject:iv];
[self addSubview:iv];
}
return ivs;
}
现在,当我像这样将这个自定义视图添加到我的主视图时,什么也没有发生:
CSImageViews *imageViews = [[CSImageViews alloc] initWithFrame:frame withNode:node];
[view addSubview:imageViews];
但是,如果我首先将此“csimageviews”容器添加到新的 uiview 中,则会出现:
CSImageViews *imageViews = [[CSImageViews alloc] initWithFrame:frame withNode:node];
UIView *v = [[UIView alloc] initWithFrame:frame];
[v addSubview:imageViews];
[view addSubview:v];
想法?