如何在导航和选项卡控制器中正确添加UITableView?(How to properly add a UITableView inside a nav and tab controller?)

编程入门 行业动态 更新时间:2024-10-27 23:20:43
如何在导航和选项卡控制器中正确添加UITableView?(How to properly add a UITableView inside a nav and tab controller?)

我有一个导航设置,顶部有一个UITabBarController。 然后我有一个选项卡,它通过创建放置到UINavigationController中的UIViewController实例化,如下所示:

UIViewController *testVC = [UIViewController new]; // Has UITableView as subview UINavigationController *testNavVC = [[UINavigationController alloc] initWithRootViewController:testVC]; [self setViewControllers:@[testNavVC]];

arris的问题在于testVC UIViewController中的UITableView。 该表在顶部正确显示,并且正确位于UINavController的导航栏下方。 但是,当您将表格视图滚动到底部时,表格视图中的最后一行将被截断在屏幕底部。 我发现我可以将底部内容插入设置为100(值将根据行高度而不同)以正确显示内容。 我觉得我不应该这样做,我正在寻找更好的解决方案。

如何正确添加以这种方式嵌套的UITableView?

作为旁注,当使用UITableViewController而不是带有添加的UITableView的UIViewController时,这一切都能正常工作。 在我的情况下,我需要使用后一种选择。

I have a navigation setup where at the top there is a UITabBarController. I then have a tab, which is instantiated by creating a UIViewController placed into a UINavigationController like so:

UIViewController *testVC = [UIViewController new]; // Has UITableView as subview UINavigationController *testNavVC = [[UINavigationController alloc] initWithRootViewController:testVC]; [self setViewControllers:@[testNavVC]];

The problem that arrises is with the UITableView inside the testVC UIViewController. The table displays properly at the top and is correctly situated underneath the UINavController's nav bar. When you scroll the table view to the bottom, however, the final rows in the table view will be cut off at the bottom of the screen. I found out that I can set the bottom content inset to 100(value will differ based on row height) to correctly display the content. I don't feel like I should need to do that though, and am looking for a better solution.

How can I properly add a UITableView that is nested in this way?

As a side note this all works correctly when using a UITableViewController rather than a UIViewController with the added UITableView. In my case I am needing to use the latter option.

最满意答案

您可以尝试使用bottomLayoutGuide属性调整UITableView底部插入而无需硬编码:

tableView.contentInset = UIEdgeInsetsMake(0.0, 0.0, self.bottomLayoutGuide.length, 0.0);

它表示内容的最低垂直范围,可以在iOS 7中使用。

作为替代方法,您可以使用此值为UITableView创建底部NSLayoutConstraint。

All of my code was done programmatically and the problem ended up being that I setup the UITableView with the views frame. I switched it over to use autolayout instead and it worked great!

更多推荐

本文发布于:2023-07-22 19:37:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1222829.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:选项卡   器中   正确   如何在   UITableView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!