Ios 如何将tableview单元格中的字体颜色更改为可变UIColor?
我在这里添加颜色,但它没有在单元格中反射Ios 如何将tableview单元格中的字体颜色更改为可变UIColor?,ios,objective-c,uitableview,fonts,colors,Ios,Objective C,Uitableview,Fonts,Colors,我在这里添加颜色,但它没有在单元格中反射 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Ce
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.font =[UIFont systemFontOfSize:14];
//cell.textLabel.textColor = theFontColor;//this does not work
//cell.textLabel.textColor = [UIColor whiteColor];//this works
// Configure the cell.
[self configureCell:cell atIndexPath:indexPath];
return cell;
}
编辑
comfigureCell覆盖了颜色。抱歉,这是一个真正的noob错误。您是否已将ontcolor定义为UIColor 例如,您应该执行以下操作:
UIColor *theFontColor = [UIColor colorWithRed:64.0f/255.0f green:58.0f/255.0f blue:43.0f/255.0f alpha:1.0f];
…然后使用它检查-configureCell:atIndexPath:是否未覆盖您先前设置的颜色。假设设置了ontcolor,则所述方法应该可以工作。感谢Warkst确认它可以工作,我运行了一遍,发现虽然设置了ontcolor,但它首先在索引路径中运行cellForRowAtIndexPath,并导致了一个NSInternalInconsistencyException。我设置了ontcolor,但这是在我尝试在cellForRowAtIndexPath中使用它之后。谢谢你的帮助:)