简体   繁体   English

如何在“自定义表格视图”单元格下创建表格视图

[英]How can I Create a Tableview Under Custom Tableview cell

I am just thinking. 我只是在想 Suppose, i have a tableview which have custom cell. 假设我有一个具有自定义单元格的tableview。 It's simple. 这很简单。 But My idea is that, when i click a tableview cell then another tableview is appear under that tableview cell, and again i click that cell then that sub tableview disappear. 但是我的想法是,当我单击一个表格视图单元格时,另一个表格视图出现在该表格视图单元格下,然后再次单击该表格单元,然后该子表格视图消失了。 Similarly when i click second cell than work same. 同样,当我单击第二个单元格而不是工作相同。 Is it possible? 可能吗? Please Provide me any idea or reference. 请提供任何想法或参考。

如果要显示其他单元格信息,则可以在单击的单元格索引路径之后添加更多单元格。

This is entirely possible, you're talking about Expandable cells . 这完全有可能,您正在谈论Expandable cells

My example here 我的例子在这里

The general idea is that your custom cell has a tableview at the bottom of the cell, and what you do is just change the cell height to display said tableview, on tap. 通常的想法是,您的自定义单元格在单元格底部具有一个表格视图,而您要做的只是更改单元格高度以在点击时显示该表格视图。

It's not easy, I'm not gonna lie it took us a while to do it, but we managed, and I'm telling you, it's very possible. 这并不容易,我不会撒谎,这花了我们一段时间,但我们设法做到了,我告诉你,这很有可能。

You can find a lot of help using the Expandable Cell keywords. 使用Expandable Cell关键字可以找到很多帮助。

Note that you're gonna find yourself handling a lot : 请注意,您会发现自己需要处理很多事情:

  • What to do when the expanding cells is shown off screen? 在屏幕上显示扩展单元时该怎么办?
  • What to do when you're expanding the first/last cells ? 扩展第一个/最后一个单元格时该怎么办?
  • What to do when expanding another cell ? 扩展另一个单元格时该怎么办?
  • What to do when scrolling inside that cell (a scrollview inside a scrollview !) 在该单元格内滚动时该怎么做(scrollview内的scrollview!)

There are many cases where it'll work, but won't work fine, and there is gonna be a lot of fine tuning. 在许多情况下,它可以工作,但不能正常工作,并且会有很多微调。 Specially in our case where we have rounded corners, but only when the cell is expanded, and not in cases where it's the last or first cell (next to section header). 特别是在我们有圆角的情况下,但仅当单元格被扩展时,而不是在最后一个或第一个单元格(节标题旁边)的情况下才如此。

They look cool and make you feel proud, but don't say to your PM it'll be done in a week, because it's a pain to build. 它们看起来很酷,让您感到自豪,但不要对您的PM表示会在一周内完成,因为构建起来很麻烦。

Create a custom table view cell class CustomTableViewCell by subclassing UITableViewCell class. 通过子类化UITableViewCell类,创建一个自定义表格视图单元格类CustomTableViewCell And system will generate CustomTableViewCell.h, CustomTableViewCell.m, CustomTableViewCell.xib files for you. 系统将为您生成CustomTableViewCell.h,CustomTableViewCell.m,CustomTableViewCell.xib文件。

Add protocols UITableViewDataSource and UITableViewDelegate in your CustomTableViewCell.h and implement the required methods in CustomTableViewCell.m files 在CustomTableViewCell.h中添加协议UITableViewDataSource和UITableViewDelegate,并在CustomTableViewCell.m文件中实现所需的方法

Add a method for setting datasource and use the datasource for updating the table. 添加用于设置数据源的方法,并使用该数据源更新表。

NOTE: 注意:

  • Handle table-dequeue mechanism properly, otherwise you will end up with weird issues that may take time to investigate and resolve. 正确处理表出队机制,否则您将遇到一些奇怪的问题,可能需要花费一些时间进行调查和解决。
  • If you use this custom cell for all the cells in your parent table then the gestures will only listened by the child table. 如果将此自定义单元格用于父表中的所有单元格,则手势将仅由子表侦听。 So plan for that too. 所以也要为此计划。

Please visit my blog for the sample code. 请访问我的博客以获取示例代码。 https://myioslearnings.blogspot.in/2017/03/nested-table-view-in-ios-objective-c.html https://myioslearnings.blogspot.in/2017/03/nested-table-view-in-ios-objective-c.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM