动态添加 UITableView 到 UITableViewCell

发布于 2025-01-02 12:52:23 字数 1066 浏览 0 评论 0原文

我想动态添加一个UITableViewUITableViewCell,当我点击UITableViewCell时,它会改变它的高度并显示一个UITableView< /code> 在其中,当我再次单击 UITableViewCell 时,它将隐藏 UITableView

为此,我执行了以下操作:

  1. 使用 nib 文件创建自定义 UITableViewCell
  2. 将其加载到主 UITableView 中,并在展开之前调整我想要显示的信息。
  3. 实现 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 来处理选定的 UITableViewCell
  4. 启动第二个 UITableView (它是一个 UITableViewController,使用 nib 文件创建它),调整所选 UITableViewCell 的大小以适应新的大小(展开它尺寸)。
  5. 使用 [selectedCell.contentView addSubview:desc.view]; 添加 UITableView
  6. 重新加载主 UITableView

但是,它不起作用,我所拥有的只是一个大小正确的空白空间。我使用了 [tableView addSubview:desc.view]; 但它是在主 UITableView 内添加 UITableView ,而不是在选定的单元格内。

注意:添加的 UITableView 不可滚动,当我单击其中一个单元格时,它会将我导航到另一个视图。

任何提示将不胜感激。 提前谢谢。

I wanna add a UITableView to UITableViewCell dynamically, when i click on the UITableViewCell, it will change it's height and display a UITableView inside it, and when i click on the UITableViewCell again, it will hide the UITableView.

To do that, i did the following:

  1. Create a custom UITableViewCell with a nib file.
  2. Load it to the main UITableView with adjusting the information i wanna display it before expanding it.
  3. Implement the - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath to handel the selected UITableViewCell.
  4. Initiate the second UITableView (it's a UITableViewController, created it with a nib file), resize the selected UITableViewCell to fit the new size (expand it's size).
  5. Adding the UITableView using [selectedCell.contentView addSubview:desc.view];
  6. Reload the main UITableView.

BUT, it didn't work, all i've got is an empty space with a correct size. i've used [tableView addSubview:desc.view]; but it's add the UITableView inside the main UITableView, not inside the selected cell.

Note: the added UITableView is not scrollable and when i click on one of it's cell it will navigate me to another view.

Any hint will be appreciated.
thx in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

可爱暴击 2025-01-09 12:52:23

就像索斯伯恩所说,我使用 UITableView 而不是 UITableViewController 并在

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:( NSIndexPath *)indexPath

因为每次用户选择一个单元格时我都会调用 [tableView reloadData]

Like sosborn said, i used a UITableView instead of UITableViewController and added the new table view in

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

cause i was calling the [tableView reloadData] every time the user select a cell.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文