2011-09-09 23 views
1

的子类不显示我有,我想展现一个UIImageView和几个UILabels自定义视图(UIView的子类)。 imageView与FaceBook异步传递,标签从特定方法获取文本。问题在于,即使imageView在到达时呈现成功,标签也不会显示。 让我告诉你的代码UILabels中的UIView

@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运行的方法绘制的方法递送。 最后,整个视图由addSubView在上海华加入。

Thanx提前

+0

添加标签为视图像这样子视图[self.view addSubview:self.lbl4]。 – Prajan

+0

是否showLbl1和这样的方法被调用? – Madhu

+0

@ozzotto:如果有任何疑问,你能帮我吗? – Prajan

回答

1

试着画标签边界,看看他们......另外,请检查你有没有尤伯杯泄漏,你有一个的alloc init和从未释放标签以及使用该二传手,所以你正在做一个双重分配初始化。