xcode 在 UITableViewCell 中添加 UITableView

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31065920/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 07:22:29  来源:igfitidea点击:

adding UITableView inside UITableViewCell

iosxcodeuitableview

提问by Pradumna Patil

I am working on custom UITableViewCellwhere I want to add UITableViewinside UITableViewCellso is there any controller available to do the same

我正在定制UITableViewCell我想在UITableView里面添加的地方,UITableViewCell所以是否有任何控制器可以做同样的事情

This is the image of what I want to add in my project

这是我想在我的项目中添加的图像

enter image description here

在此处输入图片说明

This is expandable UITableViewwhere after clicking first row inside table and buttons are expanded.

这是可扩展的UITableView,在单击表格内的第一行和按钮后展开。

So if any similar controller is available please suggest me.

因此,如果有任何类似的控制器可用,请建议我。

Thanks in advance.

提前致谢。

回答by Doro

Apple does not recommend table views to be added as subviews of other scrollable objects. If you want to develop such thing, here are the steps for you:

Apple 不建议将表视图添加为其他可滚动对象的子视图。如果你想开发这样的东西,这里是你的步骤:

  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];
    
  1. 在表格视图中为“表格视图”创建单独的部分
  2. 该部分的第一行 - 您的可点击行
  3. 当用户触摸一行时,通过 处理它- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  4. 通过修改数据源数组将其他单元格插入此部分。
  5. 重新加载部分或进行更新,

    作为

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

回答by Neal Ehardt

I'll advise against nesting table views. As a user, it's frustrating when one scrollable entity sits inside another scrollable entity. When you swipe, you're never quite sure how the content will behave. It can take several swipes to get from one end of the parent to the other. It matters how you time your swipes. It just sucks to use.

我会建议不要嵌套表视图。作为用户,当一个可滚动实体位于另一个可滚动实体内时,会感到沮丧。当您滑动时,您永远无法确定内容的行为方式。从父级的一端到另一端可能需要多次滑动。您如何安排滑动时间很重要。它只是很糟糕使用。

Try this approach of expanding a table view's sections Expand/collapse section in UITableView in iOS

尝试这种扩展表格视图部分的方法在 iOS 中的 UITableView 中展开/折叠部分

Good luck!

祝你好运!

回答by Mujahed Ansari

-> Take separate section for UITableView you want to add view like as tableView.

-> 为 UITableView 单独添加一个部分,你想像 tableView 一样添加视图。

-> Take the first row of that section.

-> 取该部分的第一行。

-> Override the delegate method of UITableView. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;

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

-> In this method update data of tableview and Reload that section.

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

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

回答by Manoj Kumar

With headers, you can achieve the same. This answer should help you out,

使用标题,您可以实现相同的目标。这个答案应该可以帮到你,

Expand/collapse section in UITableView in iOS

iOS 中 UITableView 中的展开/折叠部分