如何在另一个表对象中显示所选单元格的子单元格? [英] How to show child cells of a selected cell in another table object?

查看:155
本文介绍了如何在另一个表对象中显示所选单元格的子单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个分组表视图,每个组中有多个单元格。我想要的是,当用户选择任何perticular单元格;我想显示特定选定单元格的子元素。

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.

例如:如果用户选择A我应该显示A1,A2,A3...或B然后它应该显示B1,B2 ,B3... ** 在另一个视图控制器的表对象中。**

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.**

值。

推荐答案

在第二个视图控制器中创建属性

In your second view controller create a property

@property (nonatomic) NSIndexPath *parentIndex;

并将其合并到.m文件中

and synthesize it in .m file

@synthesize parentIndex;

在您的第一个tableview控制器中创建一个ivar

In your first tableview controller create an ivar

NSIndexPath *passIndexPath;

和您的表委托

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

现在实现以下函数, p>

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
    }
}

现在在您的SecondView控制器中借助parentIndex你知道,哪一节选择哪一行,因此

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.

希望这将帮助你,

这篇关于如何在另一个表对象中显示所选单元格的子单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆