настоящего времени у меня следующий код для моего cellForRowAtIndexPath на моем UITableView:UITableViewCell Content View - Добавление UILabels
- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString* CellIdentifier = @"Cell";
UILabel* nameLabel = nil;
UILabel* valueLabel = nil;
UILabel *percentLabel = nil;
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];
if (cell == nil)
{
inthere = YES;
cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault
reuseIdentifier: CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
nameLabel = [[[UILabel alloc] initWithFrame:CGRectMake(7.0, 0.0, 140.0, 44.0)] autorelease];
nameLabel.tag = 21;
nameLabel.font = [UIFont systemFontOfSize: 12.0];
nameLabel.textAlignment = UITextAlignmentLeft;
nameLabel.textColor = [UIColor darkGrayColor];
nameLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight;
nameLabel.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview: nameLabel];
valueLabel = [[[UILabel alloc] initWithFrame: CGRectMake(165.0, 0.0, 80, 44.0)] autorelease];
valueLabel.tag = 22;
valueLabel.font = [UIFont systemFontOfSize: 11];
valueLabel.textAlignment = UITextAlignmentRight;
valueLabel.textColor = [UIColor blueColor];
valueLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight;
valueLabel.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview: valueLabel];
percentLabel = [[[UILabel alloc] initWithFrame: CGRectMake(245, 0.0, 65, 44.0)] autorelease];
percentLabel.tag = 24;
percentLabel.font = [UIFont systemFontOfSize: 12];
percentLabel.textAlignment = UITextAlignmentRight;
percentLabel.textColor = [UIColor blueColor];
percentLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight;
percentLabel.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview: percentLabel];
}
else
{
nameLabel = (UILabel*)[cell.contentView viewWithTag:21];
valueLabel = (UILabel*)[cell.contentView viewWithTag:22];
percentLabel = (UILabel *)[cell.contentView viewWithTag:24];
}
...and then I initialize the text of each of these three labels...
}
Но то, что я хотел бы сделать, это эти три этикеток быть разными цветами в зависимости на ячейке. Например, все ячейки в разделе 3 должны иметь красные именаLabels, и все ячейки в разделе 5 должны иметь зеленые значенияLabels. Но если я вставить это в код после того, как я инициализировать текст всех меток:
if(indexPath.section==3) {
nameLabel.textColor = [UIColor redColor];
}
if(indexPath.section==5) {
valueLabel.textColor = [UIColor greenColor];
}
тогда все испортится и таблица все Glitchy, с текстом, находясь в необычных местах и этикетки быть неправильные цвета, и несколько случайный взгляд.
Как я могу указать цвета этих трех меток для каждой отдельной ячейки в моей таблице?
Вы можете поставить скриншот этого glitchyness? –
нет действительно. Это своего рода частная информация. Но ясно, что контентные представления смешиваются и не очищаются должным образом или что-то в этом роде. – CodeGuy
Вы уверены, что текст в нечетных местах или только что цвета неправильные? – Anna