动态添加 UITableView 到 UITableViewCell
我想动态添加一个UITableView
到UITableViewCell
,当我点击UITableViewCell
时,它会改变它的高度并显示一个UITableView< /code> 在其中,当我再次单击
UITableViewCell
时,它将隐藏 UITableView
。
为此,我执行了以下操作:
- 使用 nib 文件创建自定义
UITableViewCell
。 - 将其加载到主
UITableView
中,并在展开之前调整我想要显示的信息。 - 实现
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
来处理选定的UITableViewCell
。 - 启动第二个
UITableView
(它是一个UITableViewController
,使用 nib 文件创建它),调整所选UITableViewCell
的大小以适应新的大小(展开它尺寸)。 - 使用
[selectedCell.contentView addSubview:desc.view];
添加UITableView
- 重新加载主
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:
- Create a custom
UITableViewCell
with a nib file. - Load it to the main
UITableView
with adjusting the information i wanna display it before expanding it. - Implement the
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
to handel the selectedUITableViewCell
. - Initiate the second
UITableView
(it's aUITableViewController
, created it with a nib file), resize the selectedUITableViewCell
to fit the new size (expand it's size). - Adding the
UITableView
using[selectedCell.contentView addSubview:desc.view];
- 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
就像索斯伯恩所说,我使用
UITableView
而不是UITableViewController
并在- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:( NSIndexPath *)indexPath
因为每次用户选择一个单元格时我都会调用
[tableView reloadData]
。Like sosborn said, i used a
UITableView
instead ofUITableViewController
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.