我有一个带有自定义单元格的tableview,它有2个标签,我正在更改选项卡和视图控制器以编程方式我在更新列表后调用了[tablview reloadData]
。但它只是更新一个标签值。这是 cellForRowAtIndexPath :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TimesheetCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TimesheetCell"];
Timesheet *t = (self.timesheetArray)[indexPath.row];
cell.timesheetTitle.text = t.date;
cell.hours.text = [NSString stringWithFormat:@"%d", t.hours];
NSLog(@"%d", t.hours);
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"EEEE, MMMM d";
NSString *currentDate = [formatter stringFromDate:[NSDate date]];
NSLog(@"%@",t.date);
if([t.date isEqualToString:currentDate]){
cell.timesheetTitle.textColor = [UIColor colorWithRed:0 green:0.478431 blue:1.0 alpha:1.0];
cell.hours.textColor = [UIColor colorWithRed:0 green:0.478431 blue:1.0 alpha:1.0];
}
if(_changeCellToBlack)
{
cell.timesheetTitle.textColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1.0];
cell.hours.textColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0];
}
if (indexPath.row == 7) {
[cell.timesheetTitle setFont:[UIFont fontWithName:@"Avenir-Black" size:19]];
[cell.hours setFont:[UIFont fontWithName:@"Avenir-Black" size:19]];
[cell setAccessoryType:UITableViewCellAccessoryNone];
if (t.hours < 40) {
cell.timesheetTitle.textColor = [UIColor redColor];
cell.hours.textColor = [UIColor redColor];
}
}
return cell;
}
小时标签未更新其值,我已从列表中记录值,其中包含小时值。
答案 0 :(得分:0)
花了4个小时后,我发现了这个问题。我的代码中的问题只是更改cell.hours.textColor
的alpha,只是更改了这一行:
cell.hours.textColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1.0];