0
我似乎無法弄清楚如何將不同顏色的文本添加到我的表格視圖單元格的右側。這是我添加的代碼。爲表格視圖單元格添加正確的細節
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *informationTableIdentifier = @"InformationCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:informationTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:informationTableIdentifier];
}
[cell.textLabel setFont:[UIFont systemFontOfSize:15]];
[cell.textLabel setTextColor:[UIColor blackColor]];
if (indexPath.section == 0) {
cell.textLabel.text = [infoCellFirstSection objectAtIndex:indexPath.row];
}
if (indexPath.section == 1) {
if (indexPath.row == 3 || indexPath.row == 3) {
cell.detailTextLabel.text = @"@SykesHarvey";
[cell.detailTextLabel setTextColor:[UIColor colorWithRed:0.48 green:0.93 blue:0.25 alpha:1.0]];
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:informationTableIdentifier];
}
cell.textLabel.text = [infoCellSecondSection objectAtIndex:indexPath.row];
}
if (indexPath.section == 2) {
if (indexPath.row == 2 || indexPath.row == 3) {
[cell.textLabel setFont:[UIFont systemFontOfSize:14]];
[cell.textLabel setTextColor:[UIColor grayColor]];
cell.textLabel.numberOfLines = 0;
cell.backgroundColor = [UIColor clearColor];
[cell setAccessoryType:UITableViewCellAccessoryNone];
}
cell.textLabel.text = [infoCellThirdSection objectAtIndex:indexPath.row];
}
if (indexPath.section == 3) {
cell.textLabel.text = [infoCellFourthSection objectAtIndex:indexPath.row];
}
if (indexPath.section == 4) {
cell.textLabel.text = [infoCellFifthSection objectAtIndex:indexPath.row];
}
return cell;
}
所有這一切都呈現爲但我想它說@SykesHarvey在開發電池的右側。請有人可以幫忙嗎?
我不明白你在做什麼:你的情況與問題,你在做你試圖設置你正在做的電池一個全新的分配/初始化的detailsText後,對不對?請注意'cell.detailsText'應該是'nil',因爲沒有'detailsText'和'UITableViewCellStyleDefault' – Larme
你能詳細解釋一下嗎?到底什麼是你的問題? –