У меня есть пользовательское представление (подкласс UIView), в котором я хочу показать UIImageView и несколько UILabels. 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];
}
Изображение доставляется с помощью метода, который выполняется executeSelectorInBackground, и отрисовывается с помощью метода, который выполняется executeSelectorOnMainThread.
Наконец, весь вид добавляется addSubView в superView.
Спасибо заранее