0

First of all,let me be clear on the issue.

I CAN expand and collapse a UITableViewCell. I am using the following code:

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSIndexPath *indexPath1 = [NSIndexPath indexPathForRow:indexPath.row inSection:0];
    [self addOrRemoveSelectedIndexPath:indexPath1];
}

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    [self addOrRemoveSelectedIndexPath:indexPath];
}

- (void)addOrRemoveSelectedIndexPath:(NSIndexPath *)indexPath {
    BOOL containsIndexPath = [self.selectedIndexPaths containsObject:indexPath];
    if (containsIndexPath) {
        [self.selectedIndexPaths removeObject:indexPath];
    }else{
        self.selectedIndexPaths = [NSMutableArray new];
        [self.selectedIndexPaths addObject:indexPath];
    }
    [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}

My Issue is: When I expand the cell, I want to show a custom view at the bottom of the cell. I have created my custom view with XIB. But I don't know how to add and remove it with then tapped cell.

So far I simply tried adding it with cell in didSelectRowAtIndexpath:

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSIndexPath *indexPath1 = [NSIndexPath indexPathForRow:indexPath.row inSection:0];
    [self addOrRemoveSelectedIndexPath:indexPath1];

    LearnDetailCell *cell1 = (LearnDetailCell*)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row inSection:0]];
    ExpandView *expView = [[ExpandView alloc] init];
    [cell1 addSubview:expView];
}

But it is not working. Is my task possible?

Michaël Azevedo
  • 3,874
  • 7
  • 31
  • 45
  • Possible duplicate of [How do you load custom UITableViewCells from Xib files?](http://stackoverflow.com/questions/540345/how-do-you-load-custom-uitableviewcells-from-xib-files) – Teja Nandamuri Mar 17 '16 at 12:48
  • You need to add the xib to table cell, and u follow the same way as u do now. – Teja Nandamuri Mar 17 '16 at 12:49
  • @TejaNandamuri No. it is not the duplicate of that question. I can load my cell from the xib. My issue is when i have to expand that cell, I need to show another xib i.e. UIVIew with that cell. –  Mar 17 '16 at 13:03
  • 1
    are u saying that you already loaded a xib on table view and on selecting a cell, you want to show another xib as table cell ? – Teja Nandamuri Mar 17 '16 at 13:06
  • do you want to expand the same cell what was selected ? – MD. Mar 17 '16 at 13:14
  • @TejaNandamuriYes. Thats what am saying –  Mar 17 '16 at 13:36
  • First of all Cell update logic must be on cellForRowAtIndexPath. On didSelectRowAtIndexPath you have to call reloadData, that conseguently will call cellForRowAtIndexPath. On cellForRowAtIndexPath you say how to render any single cell of your tableView – christian mini Mar 19 '16 at 07:37

0 Answers0