如何组合UITableView与其他部分(uilabels和uibuttons),以便所有内容滚动

时间:2015-07-30 02:12:31

标签: ios uitableview uiviewcontroller uiscrollview uicontainerview

This is one picture of the layout I am building. The orange line marks the beginning of the tableview. In this screen, each picture represents a different table cell.

这就是我对设计的需求。

  1. 页面内容需要自动展开(在底部),具体取决于tableview的大小。

  2. 所有页面内容都需要一起滚动...而不是只是TableView滚动和滚动的tableview内容位于页面顶部的后面。

  3. 我尝试过的方法:

    1. 在顶部使用容器,在底部使用tableview。问题:当TableContent滚动时,容器保持静止。

    2. (1.失败后)在UIScrollView中使用容器(对于橙色线以上的部分)和tableview获取底部内容。问题:容器和tableview仍然存在重叠,而不是所有内容都滚动在一起。

    3. 有没有人有任何关于最佳方法的建议?

      非常感谢你!提前感谢任何帮助。当然,如果你给我正确答案,我会认为你是正确的,并给你很好的反馈 亚历克斯

1 个答案:

答案 0 :(得分:0)

如果有人遇到此问题,解决此问题的一种方法是遵循本教程:http://www.ioscreator.com/tutorials/customizing-headers-footers-table-view-ios7

总结:

  1. 在表视图的属性检查器下,再添加一个原型单元格。
  2. enter image description here

    2。 在标题单元格的属性检查器中,确保添加标识符。就我而言,它被称为 HistoryHeaderCell

    enter image description here

    3。 添加任何UI组件 - 按钮,标签等以及任何约束到此视图单元格

    1. 在tableViewController代码中添加以下内置函数
    2. 覆盖func tableView(tableView:UITableView,viewForHeaderInSection section:Int) - > UIView? {}

      ...我的全部功能如下:

       override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
            let  headerCell =   tableView.dequeueReusableCellWithIdentifier("HistoryHeaderCell") as!  HistoryHeaderCell
            self.tableView.tableHeaderView = headerCell;
            return headerCell
      

      } 注意...行 self.tableView.tableHeaderView = headerCell; 是为了在滚动tableView时标题单元格移动!希望这对某人有用:)