Ios 根据文本单元格的值更改其颜色

Ios 根据文本单元格的值更改其颜色,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我想更改UITableView中单元格文本的颜色 当我尝试使用if进行条件格式化时,它不起作用 以下是我正在尝试的代码: - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return nomearray.count; } - (void)tableView: (UITableView*)tableView willDisplayCell: (UI

我想更改UITableView中单元格文本的颜色

当我尝试使用if进行条件格式化时,它不起作用

以下是我正在尝试的代码:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
        return nomearray.count;
}

- (void)tableView: (UITableView*)tableView willDisplayCell: (UITableViewCell*)cell forRowAtIndexPath: (NSIndexPath*)indexPath
{

cell.textLabel.textAlignment = UITextAlignmentRight;


if(indexPath.row % 2 == 0) {

    cell.backgroundColor = [UIColor colorWithRed:(240/255.0) green:(240/255.0) blue:(240/255.0) alpha:1];}

else {
    cell.backgroundColor = [UIColor whiteColor];}

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableItem";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}


if (risco == 1) {[cell.textLabel setTextColor: [UIColor colorWithRed:(60/255.0) green:(169/255.0) blue:(133/255.0) alpha:1]];} else {

    if (risco == 2) {[cell.textLabel setTextColor: [UIColor colorWithRed:(255/255.0) green:(200/255.0) blue:(0/255.0) alpha:1]];} else {

        if (risco == 3) {[cell.textLabel setTextColor: [UIColor colorWithRed:(150/255.0) green:(50/255.0) blue:(50/255.0) alpha:1]];}}}



 cell.textLabel.text = [nomearray objectAtIndex:indexPath.row];

return cell;

}

我认为问题在于您的if条件不满足,因为整数值设置不正确。因此,只需设置risco integer的属性,然后检查,您尝试了吗?

这段代码在哪里?在什么方法中?risco是一个整数变量,它可以假设3个值,1、2或3。我想要的是单元格中文本的颜色根据该变量的值而改变,我将代码放在上面的-UITableViewCell tableView:UITableView*tableView cellForRowAtIndexPath:NSIndexPath*indexPath中,但不起作用。我也尝试了-voidtableView:UITableViewtableView将显示单元格:UITableViewCell*单元格用于rowatindexpath:NSIndexPath*indexPath方法!你的手机是定制的吗?如果不是,则使用文本标签或详细文本标签来介绍文本?我认为整个方法的代码将是有用的答案。我将编辑帖子,并把整个方法。等一下!谢谢你的回复!你完全正确,伙计!!问题在于正确设置risco风险var!非常感谢你!!!