【问题标题】:Autolayout issues with UITableView Footer, Storyboards, and Xcode 6UITableView 页脚、情节提要和 Xcode 6 的自动布局问题
【发布时间】:2015-04-17 14:01:47
【问题描述】:

我正在尝试通过 Storyboard 向我的 UITableView 添加页脚视图,但 Autolayout 不断绘制的页脚视图比我在 Storyboard 中调整视图的大小要大得多。这似乎是由页脚视图中包含的 UIButton 上的 Autolayout 约束引起的,尽管没有任何约束组合(我已经尝试过几个)导致页脚视图的大小正确,即使我在页脚中正确调整了 UIButton 的大小查看。

问题截图(页脚视图为白色背景):

我在这个特定实例中使用的约束(尽管请记住,我已经尝试了几个,包括为 UIButton 定义了高度的约束 - 当我设置 UIButton 的高度时 UIButton 正确绘制,但页脚视图仍然由于某种原因巨大):

想法?解决方案?在使用 Storyboard 之前,我已经将页脚视图与 Storyboard 一起使用,没有任何问题,尽管从来没有使用大小类。

【问题讨论】:

  • 更新:我可以让页脚视图显示正确高度的唯一编程方法是在 viewDidLayoutSubviews 中将页脚视图的框架设置为正确的高度,进一步确认 Autolayout 计算错误高度的原因我无法理解。但是,TableView 仍然假定现有高度的页脚,这意味着这不是一个解决方案。想法?
  • 你在情节提要中将页脚的高度设置为多少?看起来你已经把它设置得很大了。
  • 页脚高度设置正确(44 点) - 请参阅问题中的屏幕截图。

标签: ios xcode uitableview autolayout xcode-storyboard


【解决方案1】:

希望这会有所帮助:

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)

    var footerView  = self.tableView.tableFooterView! as UIView
    var frame       = footerView.frame

    frame.size.height = 30
    footerView.frame = frame

    self.tableView.tableFooterView! = footerView
}

【讨论】:

    【解决方案2】:

    我也有同样的问题。当你有导航栏时,它看起来像 Xcode 的一个错误

    我是这样解决的……

    footerView = tableView.tableFooterView
        tableView.tableFooterView = nil
        tableView.addSubview(footerView)
        footerView.frame.size.height = 100
    

    【讨论】:

      猜你喜欢
      • 2015-08-24
      • 1970-01-01
      • 2015-03-17
      • 2014-12-04
      • 1970-01-01
      • 1970-01-01
      • 2014-11-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多