-1

I have a tableview which contains:

-2 custom cells : redCell and blueCell

-2 buttons : redButton and blueButton at bottom of the screen.

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

        if(indexPath.section == 0) {
            RedTableViewCell *redCell = (RedTableViewCell *)[tableView dequeueReusableCellWithIdentifier:BlockListTableViewCellIdentifier forIndexPath:indexPath];
            Red *red = (Red *)[self.reds objectAtIndex:indexPath.row];

            return redCell;
        }
        else
        {
            BlueTableViewCell *blueCell = (BlueTableViewCell *)[tableView dequeueReusableCellWithIdentifier:RestBlockTableViewCellIdentifier forIndexPath:indexPath];
            Blue *blue = [self.blues objectAtIndex:indexPath.row];

            return blueCell;
        }

        return nil;
    }

My TableView

I want that when i click redButton = redCell added ,click blueButton = blueCell added.

P/S : I don't want to change the background color, I want 2 different cells.

1 Answers1

2

I am assuming the below from your unclear questions.

The red cell contains a red button, and when you click on this red button, you want a new red cell to be added. Similarly with Blue cell.

Solution:

Inside, red(or blue) button action,

  1. Add new entry in your self.reds(or self.blues) array
  2. reload tableview

Also, check, numberofRowsinSection should return self.reds.count for section 0 and self.blues.count for other sections.

skri
  • 213
  • 3
  • 9