【问题标题】:UITableView is under the TabBarUITableView 在 TabBar 下
【发布时间】:2016-12-01 12:26:31
【问题描述】:

我有一个带有自定义单元格的自定义 UITableView(每个单元格高度为 70 像素)。

我还有一个 49px UITabBar,但它隐藏了 tableView。

我尝试将此行添加到 TableView awakeFromNib 方法中,但没有成功:

self.commentsTableView.contentInset = UIEdgeInsetsMake(0, 0, 49, 0)

知道如何解决这个问题吗?

谢谢!

【问题讨论】:

  • 你在使用故事板吗?
  • @VishalSonawane 不,我使用的是 NIB/XIB 文件
  • 您使用的是自动布局还是自动调整大小?
  • @VishalSonawane 是的,我当然使用约束
  • @BhadreshMulsaniya 我没有对此进行任何更改,所以我想我正在使用自动布局,因为它是默认选项

标签: ios objective-c swift uitableview cocoa-touch


【解决方案1】:

我不知道你到底做了什么,但试试这样:

self.edgesForExtendedLayout = UIRectEdgeAll;
self.tableview.contentInset = UIEdgeInsetsMake(0.0f, 0.0f, CGRectGetHeight(self.tabBarController.tabBar.frame), 0.0f);

我希望,这会奏效。

【讨论】:

  • 你拯救了我的一天,兄弟。太感谢了。这是正确的答案。
【解决方案2】:

尝试对 tableView 和 TabBar 使用约束,例如:

【讨论】:

    【解决方案3】:

    这在 Swift 3 中为我解决了问题。

    if let tabBarController = tabBarController {
        self.tableView.contentInset = UIEdgeInsetsMake(0.0, 0.0, tabBarController.tabBar.frame.height, 0.0);
    }
    

    【讨论】:

      【解决方案4】:

      试试这个

      self.commentsTableView.contentInset = UIEdgeInsetsMake(49, 0, 0, 0)
      self.commentsTableView.setContentOffset(CGPoint.init(x: 0, y: -49), animated: false)
      

      【讨论】:

        【解决方案5】:

        您应该使用以下代码配置相应的视图控制器以删除边缘扩展(默认为 UIRectEdgeAll)

        edgesForExtendedLayout = []
        

        【讨论】:

          【解决方案6】:

          我在处理没有半透明条的导航控制器中的表格视图时遇到了这个问题。我执行了类似于以下的设置:

          override func viewDidLoad() {
              super.viewDidLoad()
          
              // Without this there is some extra fast inertia when slowly
              // scrolling to the top.
              extendedLayoutIncludesOpaqueBars = true
          
              // Don't extend the tableview past the bottom bar, though.
              // If we do then a tab bar or bottom nav bar will block
              // content.
              edgesForExtendedLayout = [.top, .left, .right]
          }
          

          但是,我后来发现在层次结构更高的情节提要中未选中几个复选框。特别是这两个:

          选中这两个框消除了关注该视图控制器中的内容插入和布局扩展行为的需要

          【讨论】:

            【解决方案7】:

            如果您在之前的视图控制器中更改了self.hidesBottomBarWhenPushed=true,请确保在override func prepare(for segue: UIStoryboardSegue, sender: Any?) {} 中将其更改为self.hidesBottomBarWhenPushed=false

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2019-07-25
              • 1970-01-01
              • 1970-01-01
              • 2013-10-11
              • 2023-04-10
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多