-1

I have been working with the problem for 2 days.And i have refer some SO ques like Link 1 . What the problem is i have group table with 2 rows and array count section. When i scroll the table means the 4th section repeats the value of the 1st but it works good upto 3 section. Both the rows takes the value of 1st section rows

my code is :

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

Can any provide solution for that

Community
  • 1
  • 1
New Xcoder
  • 535
  • 1
  • 4
  • 14
  • I have count sections right j and k representing the corresponding cells in the sections . i.e 1st and 2nd cell – New Xcoder Jun 01 '12 at 07:55
  • But you are comparing j & k with section not with row.If j & k represents cell then you should compare it with indexPath.row not with indexPath.section. – Nuzhat Zari Jun 01 '12 at 08:01
  • Actually j&k represents cells but we have multiple sections with different value in the cells . – New Xcoder Jun 01 '12 at 08:55

1 Answers1

0

If your requirement is, you have multiple section with 2 rows/cells in each section then I would rather suggest you to code like this in 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;
}
Nuzhat Zari
  • 3,398
  • 2
  • 24
  • 36
  • But what my problem is my section is a dynamic. I do know how much section i will have. – New Xcoder Jun 01 '12 at 11:52
  • Based on your code I could see that only cell.detailTextLabel setTag:indexPath.section] is dependent on section whereas cell.detailTextLabel.text is taking constant value.So cell will show same value irrespective of section. – Nuzhat Zari Jun 01 '12 at 14:02