Как отключить определенные ячейки в зависимости от пользовательских значений uilabel? - PullRequest
0 голосов
/ 31 января 2012

В моей функции cellForRowAtIndexPath я разделил две UILabels, которые содержат значения внутри ячеек.

Допустим, например, что значения, представленные в одной ячейке, равны

Значение 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 Ответ

2 голосов
/ 31 января 2012

Используйте следующий код

-(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;            
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...