我有一个自定义视图(UIView的子类),我想在其中显示UIImageView和几个UILabel。 imageView与FaceBook异步,标签从特定方法获取文本。问题是即使imageView在到达时成功呈现,也不会显示标签。 我来告诉你代码
@interface CustomView : UIView {
UIImageView *imageView;
UILabel *lbl1;
UILabel *lbl2;
UILabel *lbl3;
UILabel *lbl4;
}
@property(nonatomic,retain) UIImageView *imageView;
@property(nonatomic,retain) UILabel *lbl1;
@property(nonatomic,retain) UILabel *lbl2;
@property(nonatomic,retain) UILabel *lbl3;
@property(nonatomic,retain) UILabel *lbl4;
实施如下:
@implementation CustomView
@synthesize imageView;
@synthesize lbl1;
@synthesize lbl2;
@synthesize lbl3;
@synthesize lbl4;
- (id)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame]))
{
self.lbl1 = [[UILabel alloc] initWithFrame:CGRectMake(65, 356, 98, 13)];
self.lbl1.backgroundColor = [UIColor clearColor];
[self addSubview:self.lbl1];
self.lbl2 = [[UILabel alloc] initWithFrame:CGRectMake(260, 356, 50, 13)];
self.lbl2.backgroundColor = [UIColor clearColor];
[self addSubview:self.lbl2];
self.lbl3 = [[UILabel alloc] initWithFrame:CGRectMake(65, 374, 92, 13)];
self.lbl3.backgroundColor = [UIColor clearColor];
[self addSubview:self.lbl3];
self.lbl4 = [[UILabel alloc] initWithFrame:CGRectMake(260, 374, 49, 13)];
self.lbl4.backgroundColor = [UIColor clearColor];
[self addSubview:self.lbl4];
}
return self;
}
请注意,标签矩形是硬编码的,为方便起见而不匹配。 设置标签文本的方法示例如下:
- (void)showLbl1:(NSString *)str withFont:(UIFont *)font andColor:(UIColor *)color
{
self.lbl1.font = font;
self.lbl1.textColor = [UIColor cyanColor];
[self.lbl1 setText:str];
}
图像通过performSelectorInBackground运行的方法传递,并使用performSelectorOnMainThread运行的方法绘制。 最后,整个视图由superView中的addSubView添加。
提前完成
答案 0 :(得分:1)
尝试绘制标签边框并查看它们的位置...还要检查你在那里的超级泄漏,你有一个alloc init并且永远不会释放标签并且还使用setter,所以你正在做一个双重alloc init。