How to show child cells of a selected cell in another table object?

情到浓时终转凉″ 提交于 2020-01-17 13:02:29

问题


I have a grouped table view with multiple cells in each group.What I want is, when user selects any perticular cell; I want to show child element of the particular selected cell.

For example: If user selects "A" then I should show "A1","A2","A3"... Or "B" then it should show "B1","B2","B3"...**In another viewcontroller's table object.**

There is no restriction on hard-coding the child values. My segue is connected from the table view to another viewcontroller.


回答1:


In your second view controller create a property

@property (nonatomic) NSIndexPath *parentIndex;

and synthesize it in .m file

@synthesize parentIndex;

In your first tableview controller create an ivar

NSIndexPath *passIndexPath;

and in your table delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    passIndexPath = indexPath;
   [self performSegueWithIdentifier:@"push_SecondTableViewController" sender:self];
}

Now implement the following function it will run right when you trigger your segue

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

    if ([[segue identifier] isEqualToString:@"push_SecondTableViewController"])
    {
      Your_SecondViewController *viewController = [segue destinationViewController];

      viewController.parentIndex = passIndexPath; 
     //Here we are passing the indexpath of the selected cell so now you can set the 
     //data of the table in second view controller
    }
}

Now in your SecondView controller with the help of parentIndex you know, which section's which row was selected and you can display the data accordingly

Same way you can even pass the data Array for your child cells.

Hope this will help you,




回答2:


It also called nested table view. Refer to this blog and the sample code is here




回答3:


You need to use concept of collapse table

checkout here the step by step explanation for expanding & collapsing sections

Expand Sections

You can also check sample code here.

Sample Code

Enjoy Programming



来源:https://stackoverflow.com/questions/13758306/how-to-show-child-cells-of-a-selected-cell-in-another-table-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!