将UITableView添加到UITableViewCell中

17

我正在开发自定义的UITableViewCell,我想在其中添加UITableView,是否有可用的控制器来实现此功能。

这是我想要添加到我的项目中的图片:

enter image description here

这是一个可以展开的UITableView,单击表格内的第一行后,按钮会展开。

如果有类似的控制器,请向我推荐。

先谢谢了。


3
可能是重复的问题,与https://dev59.com/RGQm5IYBdhLWcg3wtA0_相似。 - iAnurag
我有类似的问题,已经发布在 https://stackoverflow.com/q/45626816/6028575,请帮忙解答。 - Jaydeep Vyas
4个回答

4

苹果不建议将表视图添加为其他可滚动对象的子视图。如果您想要开发这样的功能,请按照以下步骤操作:

  1. Make separate section for your 'table view' inside your table view
  2. The first row of the section - your clickable row
  3. When the user touches a row, handle it via - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath.
  4. Insert other cells into this section by modifying your datasource array.
  5. Reload section or do an update,

    as

    [self.dataSourceArray insertObject:object atIndex:indexPath.row];
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
    [self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
    

为什么苹果不建议这样做,如果每个iOS设备中“设置”内部的WiFi列表都是这样完成的? - Josh
@Josh,其中一个原因是使用自动布局和计算嵌套可滚动对象的正确尺寸非常困难。有一种简单的方法可以避免嵌套。此外,您在哪里看到设置中嵌套的UIScrollView层次结构?这只是简单的tableview节更新(如插入/删除)。 - Doro
嗨 @Doro,当您打开iPhone的 设置> Wi-Fi 时,您可以看到第一部分(带有Wi-Fi开/关开关和活动Wi-Fi网络),以及...第二部分,其中包含一个动态增长或缩小的WiFi热点列表。我想实现完全相同的事情,但是要用其他东西代替WiFi网络。 我只对swift / ios略有了解,您知道我是否从正确的角度考虑这个问题吗? - Josh
@Josh,我知道两种方法可以做到这一点 - 使用TableView的Section和使用TableView的Header。请查看此教程http://www.appcoda.com/expandable-table-view/ - 我希望它能帮助你找到正确的方向 :) - Doro

4
我建议不要嵌套表格视图。作为用户,当一个可滚动的实体位于另一个可滚动的实体内时,这是令人沮丧的。当您滑动时,您永远不确定内容会如何行动。可能需要多次滑动才能从父级的一端到达另一端。您滑动的时间很重要。使用起来非常糟糕。
尝试使用这种方法展开表格视图的部分:在iOS中展开/折叠UITableView中的部分 祝你好运!

1

-> 为要添加视图的UITableView单独设置一个部分。

-> 取该部分的第一行。

-> 重写UITableView的委托方法。- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;

-> 在此方法中更新tableview的数据并重新加载该部分。

 [self.dataSourceArray removeObjectAtIndex:indexPath.section];
    [self.dataSourceArray insertObject:object atIndex:indexPath.section];
    [tableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationAutomatic];

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接