0

我正在尝试在 UITableViewCell 中添加一些标签和图像作为附件视图。但它没有显示在表格单元格中我的代码是

unsigned int flags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit | NSWeekdayCalendarUnit;
NSDateComponents* parts = [[NSCalendar currentCalendar] components:flags fromDate:[NSDate date]];

UILabel *lbTime = [[UILabel alloc]initWithFrame:CGRectMake(-80, -21, 99, 20)];
[lbTime setBackgroundColor:[UIColor clearColor]];
[lbTime setTextColor:[UIColor grayColor]];
[lbTime setFont:[UIFont systemFontOfSize:13]];
int hour = parts.hour;
NSString *amPm = @"Am";
if (hour>12) {
    hour = hour -12;
    amPm = @"Pm";
}
lbTime.text = [NSString stringWithFormat:@"%.02d:%.02d %@",hour,parts.minute,amPm];


UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 15, 15)];
imgView.image = [UIImage imageNamed:@"imgWhiteAero.png"];
cell.accessoryView = imgView;


UIView *view = [[UIView alloc]init];
[view addSubview:lbTime];
[view addSubview:imgView];
cell.accessoryView = view;
[view release];
[imgView release];

标签显示成功,但当我只添加图像作为附件视图时,图像不显示 cell.accessoryView = imgView;

但是当我将它添加到上面提到的代码中的 UIView 中时,它没有显示

4

0 回答 0