我在这里使用 cellForRowAtIndexPath :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
cell = [self getCellContentView:CellIdentifier];
UILabel *lbl = (UILabel*)[cell.contentView viewWithTag:1];
for (UITableViewCell *c in [tbl visibleCells])
{
// UITableViewCell *cell2 = [tbl cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
UILabel *lbl = (UILabel*)[c.contentView viewWithTag:1];
lbl.textColor = [UIColor redColor];
}
if([tbl indexPathForCell:cell].section==0)
lbl.textColor = [UIColor whiteColor];
UILabel *lblTemp1 = (UILabel *)[cell viewWithTag:1];
UILabel *lblTemp2 = (UILabel *)[cell viewWithTag:2];
//First get the dictionary object
lblTemp1.text = @"test!";
lblTemp2.text = @"testing more";
NSLog(@"%@",[tbl indexPathForCell:cell]);
return cell;
}
但是仍然使我的一些细胞变成白色而不是灰色。
如何仅将行中的第一项更改为白色?