Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何将tableview单元格中的字体颜色更改为可变UIColor?_Ios_Objective C_Uitableview_Fonts_Colors - Fatal编程技术网

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中使用它之后。谢谢你的帮助:)