0

How to use 3 different cells on one uitableview? I have 3 buttons now When i press any button then cell of table view should be changed. Please help

Mashhadi
  • 3,004
  • 3
  • 46
  • 80

1 Answers1

0

In the button's action method, save which button was tapped & reload the row in which you want to change the cell.

-(void)button1Tapped:(id)sender
{

    self.buttonIndex = 1;
    NSArray* arr = [[NSArray alloc] initWithObjects:self.indexPathOfConcernedCell, nil];
    [self.tableView reloadRowsAtIndexPaths:arr withRowAnimation:UITableViewRowAnimationNone];
    [arr release];

}

Then, in cellForRowAtIndexPath: return the cell one the basis of which button was pressed-

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

    if(indexPath == self.indexPathOfConcernedCell)
    {

    if(self.buttonIndex == 1)
             {
                  Cell1* cell = (Cell1*) [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier1"];

                  if(cell == nil)
                  {
                 cell = [[[Cell1 alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"CellIdentifier1"] autorelease];
                  } 
             }

        else if(self.buttonIndex == 2)
        {
            //do similar stuff
        }

        //do similar stuff for buttonIndex 3 here

        }
    }

    else
    {
        //your regular stuff
    }

    return cell;

    }
Michael Mrozek
  • 169,610
  • 28
  • 168
  • 175
Akshay
  • 5,747
  • 3
  • 23
  • 35