2012-01-31 28 views
0

当前在我的cellForRowAtIndexPath功能我已经subclassed两个UILabels持有单元格内的值。如何根据自定义的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;    

     } 

任何提示和/或建议如何找到亲每个条件将高度赞赏。提前致谢。

回答

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;    
} 
+0

就像一个魅力。非常感谢! – doge 2012-01-31 11:29:54

相关问题