Expand UITableView cell in UITableViewstylePlain

前端 未结 7 2052
北荒
北荒 2020-12-13 16:20

I want to expand tableview cell on it\'s click. There is a tableview in which two cells are expandable and others are not. I need when i click on expandable cell it should s

7条回答
  •  -上瘾入骨i
    2020-12-13 16:50

    Here is the complete Tutorial with Expandable UITableView

    Here’s the code snip for that.

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        if ([self tableView:tableView canCollapseSection:indexPath.section])
        {
            if (!indexPath.row)
            {
                // only first row toggles exapand/collapse
                [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
                NSInteger section = indexPath.section;
                BOOL currentlyExpanded = [expandedSections containsIndex:section];
                NSInteger rows;
    
                NSMutableArray *tmpArray = [NSMutableArray array];
    
                if (currentlyExpanded)
                {
                    rows = [self tableView:tableView numberOfRowsInSection:section];
                    [expandedSections removeIndex:section];
    
                }
                else
                {
                    [expandedSections addIndex:section];
                    rows = [self tableView:tableView numberOfRowsInSection:section];
                }
    
                for (int i=1; i

    as shown below picture

    enter image description here

    This and this one solution also help you to understand how to manage Expandable TableView

提交回复
热议问题