제가 만든 사용자 지정 TableViewCell이 있습니다. 각 셀에는 두 가지 UI 라벨이 있습니다. 또한, 내 tableView 다른 배경색 및 텍스트 색을 갖고 싶어 한 섹션이 있습니다.uitableviewcell 속성을 무시하는 데 문제가 있습니다.
지금 당장 UILabel.textColor를 사용하여 텍스트 색상을 변경할 수 없습니다. 나는 cell.textLabel.textColor로 작동하도록 만들었지 만. 또한 cell.background 색상이 작동하지 않습니다.
하단의 스위치 문 내부에서 셀 속성 변경을 수행하면 셀 속성이 변경 될 수 있었지만 셀 속성은 제대로 스크롤되지 않으므로 임의의 셀이 흰색 텍스트가됩니다. 빨간색 배경입니다. 당신은 테이블 셀을 표시하기 직전에 사용자 정의를 할 수있는
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"MyIdentifier";
UILabel* itemLabel;
UILabel* amountLabel;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
itemLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 220.0, 35.0)] autorelease];
itemLabel.tag = ITEMLABEL_TAG;
itemLabel.font = [UIFont systemFontOfSize:14.0];
itemLabel.textAlignment = UITextAlignmentLeft;
itemLabel.autoresizingMask = UIViewAutoresizingNone;
itemLabel.backgroundColor = [UIColor clearColor];
itemLabel.textColor = [UIColor blueColor]; //This doesn't work
if (indexPath.section == 4)
{
cell.textLabel.textColor = [UIColor whiteColor]; //This works
cell.backgroundColor = [UIColor redColor]; //This doesn't work
}
[cell.contentView addSubview:itemLabel];
cell.backgroundColor = [UIColor whiteColor];
amountLabel = [[[UILabel alloc]initWithFrame:CGRectMake(225.0, 0.0, 55.0, 35.0)] autorelease];
amountLabel.tag = AMOUNTLABEL_TAG;
amountLabel.font = [UIFont systemFontOfSize:14.0];
amountLabel.textAlignment = UITextAlignmentLeft;
amountLabel.textColor = [UIColor blackColor]; //This doesn't work
amountLabel.backgroundColor = [UIColor clearColor];
amountLabel.autoresizingMask = UIViewAutoresizingNone;
[cell.contentView addSubview:amountLabel];
switch (indexPath.section) {
case 0:
cell.textLabel.text = [monthlyExpenses objectAtIndex:indexPath.row];
break;
case 1:
cell.textLabel.text = [oneTimeFees objectAtIndex:indexPath.row];
break;
case 2:
cell.textLabel.text = [renters objectAtIndex:indexPath.row];
break;
case 3:
cell.textLabel.text = [travelExpenses objectAtIndex:indexPath.row];
break;
case 4:
cell.textLabel.text = @"Generate Report";
break;
}
return cell;
}