-1

我已经解决了 2 天的问题。我参考了一些 SO 问题,例如 Link 1。问题是我有 2 行和数组计数部分的组表。当我滚动表格时,意味着第 4 部分重复了第 1 部分的值,但它在 3 部分中效果很好。这两行都取第一节行的值

我的代码是:

static NSString *CellIdentifier = @"Cell";
cell = (CopyableTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[CopyableTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 
                                         reuseIdentifier:CellIdentifier] autorelease];
}

cell.delegate = self;

/*UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];

//cell.detailTextLabel.lineBreakMode=UILineBreakModeWordWrap;
cell.detailTextLabel.numberOfLines=2;
cell.detailTextLabel.font=[UIFont systemFontOfSize:14];*/


// Configure the cell...
DLog(@"");
//cell setBackgroundColor:[UIColor colorWithRed:0.7 green:0.7 blue:0.7 alpha:0.8]]
cell.textLabel.textColor = [UIColor blackColor];//[UIColor colorWithRed:0.22 green:0.33 blue:0.53 alpha:0.8];
cell.detailTextLabel.textColor = [UIColor blackColor];  
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    l=indexPath.section;

    switch (indexPath.row) {
        case 0: 
            cell.textLabel.text =@"Quantity";


            if (indexPath.section ==k) {
                    cell.detailTextLabel.text = self.qtyValue;
                    [cell.detailTextLabel setTag:indexPath.section];

            }

        break;
        case 1:
            cell.textLabel.text = @"Unit";



            if (indexPath.section ==j) {
                cell.detailTextLabel.text = [self.unitValue valueForKey:@"val"];
                [cell.detailTextLabel setTag:indexPath.section];                
            }


            break;


        default:
            break;
    }

任何人都可以为此提供解决方案

4

1 回答 1

0

如果您的要求是,您有多个部分,每个部分中有 2 行/单元格,那么我宁愿建议您在 cellforRowAtIndexPath 中编写这样的代码:

switch(indexPath.row)
{
   case 0:   
   {
      switch(indexPath.section)
      {
          case 0:
          {
             //Statement needs to execute for cell0 in section 0.
          }
            break;
          case 1:
          {
             //Statement needs to execute for cell0 in section 1.
          }
            break;
          case 2:
          {
             //Statement needs to execute for cell0 in section 2.
          }
            break;
          case 3:
          {
             //Statement needs to execute for cell0 in section 3.
          }
            break;
      } 
   }
    break;
   case 1:   
   {
      switch(indexPath.section)
      {
          case 0:
          {
             //Statement needs to execute for cell1 in section 0.
          }
            break;
          case 1:
          {
             //Statement needs to execute for cell1 in section 1.
          }
            break;
          case 2:
          {
             //Statement needs to execute for cell1 in section 2.
          }
            break;
          case 3:
          {
             //Statement needs to execute for cell1 in section 3.
          }
            break;
      } 
   }
     break;
 default:
     break;
}
于 2012-06-01T10:25:47.490 回答