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?