[英]Subclassed UIView not displaying UIImageViews added to it
因此,我有一个称为CSImageViews(uiview的子类)的类,它实际上是一行UIImageViews,包含在单个子类UIView中。
我添加了一个像这样的自定义init方法(node / 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];
有什么想法吗?
我的愚蠢错误。 在这个特定的子类UIView中,我有一个方法,每次显示其父视图控制器时都会调用该方法。 此方法实际上从视图中删除了所有子视图...因此,当我在初始视图中渲染uiimageviews时,我看不到它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.