我有一个自定义视图(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添加。

提前感谢

最佳答案

尝试绘制标签边框,看看它们在哪里。...还要检查那里的超级泄漏,您有一个alloc初始化,并且从不释放标签,也没有使用setter,所以您正在执行双重alloc初始化。

10-08 17:56