如何根据自定义uilabel值禁用某些单元格?

时间:2012-01-31 11:09:07

标签: objective-c uitableview

在我的cellForRowAtIndexPath函数中Currenly我已经将两个UILabel子类化,这些UILabel将值保存在单元格内。

让我们说例如,一个单元格中显示的值是

值1 值2

并且如果值2等于@"0,00"该单元格需要设置为已禁用并且cell.accessoryType设置为None

    -(UItableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
        {

            UITableViewCell *cell = [myTableView dequeueReusableCellWithIdentifier:CellIdentifier];

            if (cell == nil)
            {
            cell = [self getCellContentView:CellIdentifier];
            }

            UILabel *lblValues = (UILabel *)[cell viewWithTag:1];

            UILabel *lblsecValues = (UILabel *)[cell viewWithTag:2];

            lblvalues.text = [values objectAtIndex:indexPath.row];

            lblsecValues.text = [secValues objectAtIndex:indexPath.row];


            cell.accessoryType = UITableViewAccessoryDisclosureIndicator;


             /*
             if (  something..... ){

               //cell holding the `@"0,00"` 
               //cell.accessoryType = UITableViewAccessoryNone;

               //cell.setUserInteractionEnabled = NO;   


             }
             */
            return cell;            

        }

任何有关如何找到合适情况的提示和/或建议都将受到高度赞赏。提前谢谢。

1 个答案:

答案 0 :(得分:2)

使用以下代码

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [myTableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil)
    {
        cell = [self getCellContentView:CellIdentifier];
    }

    UILabel *lblValues = (UILabel *)[cell viewWithTag:1];
    UILabel *lblsecValues = (UILabel *)[cell viewWithTag:2];

    lblvalues.text = [values objectAtIndex:indexPath.row];
    lblsecValues.text = [secValues objectAtIndex:indexPath.row];

    if( [[secValues objectAtIndex:indexPath.row] isEqualToString:@"0,00"] )
    {
        cell.accessoryType = UITableViewAccessoryNone;
        cell.userInteractionEnabled = NO;   
    }
    else
    {
        cell.accessoryType = UITableViewAccessoryDisclosureIndicator;
        cell.userInteractionEnabled = YES;   
    }

    return cell;            
}