1. <small id='SikHE'></small><noframes id='SikHE'>

    1. <tfoot id='SikHE'></tfoot>
      <i id='SikHE'><tr id='SikHE'><dt id='SikHE'><q id='SikHE'><span id='SikHE'><b id='SikHE'><form id='SikHE'><ins id='SikHE'></ins><ul id='SikHE'></ul><sub id='SikHE'></sub></form><legend id='SikHE'></legend><bdo id='SikHE'><pre id='SikHE'><center id='SikHE'></center></pre></bdo></b><th id='SikHE'></th></span></q></dt></tr></i><div id='SikHE'><tfoot id='SikHE'></tfoot><dl id='SikHE'><fieldset id='SikHE'></fieldset></dl></div>

        <bdo id='SikHE'></bdo><ul id='SikHE'></ul>
      <legend id='SikHE'><style id='SikHE'><dir id='SikHE'><q id='SikHE'></q></dir></style></legend>
    2. 如果禁用滚动,您能否根据显示的行数来更新 UITableView 的内在内容大小?

      Can you get a UITableView#39;s intrinsic content size to update based on the number of rows shown if scrolling is disabled?(如果禁用滚动,您能否根据显示的行数来更新 UITableView 的内在内容大小?)
      <i id='QrFE4'><tr id='QrFE4'><dt id='QrFE4'><q id='QrFE4'><span id='QrFE4'><b id='QrFE4'><form id='QrFE4'><ins id='QrFE4'></ins><ul id='QrFE4'></ul><sub id='QrFE4'></sub></form><legend id='QrFE4'></legend><bdo id='QrFE4'><pre id='QrFE4'><center id='QrFE4'></center></pre></bdo></b><th id='QrFE4'></th></span></q></dt></tr></i><div id='QrFE4'><tfoot id='QrFE4'></tfoot><dl id='QrFE4'><fieldset id='QrFE4'></fieldset></dl></div>

        1. <legend id='QrFE4'><style id='QrFE4'><dir id='QrFE4'><q id='QrFE4'></q></dir></style></legend>
            <bdo id='QrFE4'></bdo><ul id='QrFE4'></ul>
              <tbody id='QrFE4'></tbody>
          • <tfoot id='QrFE4'></tfoot>

            • <small id='QrFE4'></small><noframes id='QrFE4'>

                本文介绍了如果禁用滚动,您能否根据显示的行数来更新 UITableView 的内在内容大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我们的 UI 有一部分是一小部分标签,旁边有颜色样本.我接手的设计在布局中有六个这样的硬编码,即使实际数据是动态的,这意味着如果我们只需要显示三个,我们必须显式隐藏三个,这也会破坏页面的平衡.更糟糕的是,这些项目"中的每一个实际上都由几个子视图组成,因此一个包含六个硬编码项目的屏幕有十八个 IBOutlets.

                We have a portion of our UI which is a small list of labels with color swatches next to them. The design I'm taking over has six of these hard-coded in the layout even though the actual data is dynamic, meaning if we only need to show three, we have to explicitly hide three, which also throws off the balance of the page. Making matters worse is each one of those 'items' is actually made up of several sub-views so a screen with six hard-coded items has eighteen IBOutlets.

                我想做的是改为使用 UITableView 来表示屏幕的这一小部分,并且由于它不会滚动,我想知道您是否可以使用 AutoLayout 来配置UITableView 的内在内容高度取决于行数.

                What I'm trying to do is to instead use a UITableView to represent this small portion of the screen, and since it won't scroll, I was wondering if you can use AutoLayout to configure the intrinsic content height of the UITableView to be based on the number of rows.

                目前我有一个测试页面,其中 UITableView 垂直限制在中心,但没有高度限制,因为我希望表格的内在内容大小反映可见行.我还禁用了在桌子上滚动.当我重新加载表时,我调用 updateConstraints.但是表格仍然没有调整大小.

                Currently I have a test page with a UITableView vertically constrained to the center, but without a height constraint because I am hoping to have the table's intrinsic content size reflect the visible rows. I have also disabled scrolling on the table. When I reload the table, I call updateConstraints. But the table still does not resize.

                注意:我们不能使用 UIStackView(它本来是完美的),因为我们必须以 iOS8 为目标,并且直到 iOS9 才引入,因此这个解决方案.

                Note: We can't use a UIStackView (which would have been perfect for this) because we have to target iOS8 and that wasn't introduced until iOS9, hence this solution.

                有没有人能够做类似我们需要的事情?

                Has anyone been able to do something similar to our needs?

                推荐答案

                好吧,与 UITextView 不同,它看起来不像 UITableView 曾经返回基于固有大小的在可见行上.但这并不是通过子类来实现的,特别是如果只有一个部分,没有页眉或页脚,并且行的高度是固定的.

                Ok, so unlike UITextView, it doesn't look like UITableView ever returns an intrinsic size based on the visible rows. But that's not that big a deal to implement via a subclass, especially if there's a single section, no headers or footers, and the rows are of a fixed height.

                class AutoSizingUiTableView : UITableView
                {
                    override func intrinsicContentSize() -> CGSize
                    {
                        let requiredHeight = rowCount * rowHeight
                        return CGSize(width: UIView.noIntrinsicMetric, height: CGFloat(requiredHeight))
                    }
                }
                

                我会让读者自己弄清楚如何获得自己的rowCount.如果您有可变高度、多个部分等,则相同.您只需要更多逻辑.

                I'll leave it up to the reader to figure out how to get their own rowCount. The same if you have variable heights, multiple sections, etc. You just need more logic.

                通过这样做,它可以很好地与 AutoLayout 配合使用.我只是希望它能自动处理.

                By doing this, it works great with AutoLayout. I just wish it handled this automatically.

                这篇关于如果禁用滚动,您能否根据显示的行数来更新 UITableView 的内在内容大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Auto layout constraints issue on iOS7 in UITableViewCell(UITableViewCell中iOS7上的自动布局约束问题)
                How to resize superview to fit all subviews with autolayout?(如何调整超级视图的大小以适应所有具有自动布局的子视图?)
                reloadData() of UITableView with Dynamic cell heights causes jumpy scrolling(具有动态单元格高度的 UITableView 的 reloadData() 导致跳跃滚动)
                What is NSLayoutConstraint quot;UIView-Encapsulated-Layout-Heightquot; and how should I go about forcing it to recalculate cleanly?(什么是 NSLayoutConstraint“UIView-Encapsulated-Layout-Height?我应该如何强制它干净地重新计算?) - IT屋-程序员
                quot;Auto Layout still required after executing -layoutSubviewsquot; with UITableViewCell subclass(“执行 -layoutSubviews 后仍需要自动布局带有 UITableViewCell 子类)
                How to format localised strings in Swift?(如何在 Swift 中格式化本地化字符串?)

                        <tbody id='4QEu3'></tbody>
                        <bdo id='4QEu3'></bdo><ul id='4QEu3'></ul>
                        <legend id='4QEu3'><style id='4QEu3'><dir id='4QEu3'><q id='4QEu3'></q></dir></style></legend>
                      • <i id='4QEu3'><tr id='4QEu3'><dt id='4QEu3'><q id='4QEu3'><span id='4QEu3'><b id='4QEu3'><form id='4QEu3'><ins id='4QEu3'></ins><ul id='4QEu3'></ul><sub id='4QEu3'></sub></form><legend id='4QEu3'></legend><bdo id='4QEu3'><pre id='4QEu3'><center id='4QEu3'></center></pre></bdo></b><th id='4QEu3'></th></span></q></dt></tr></i><div id='4QEu3'><tfoot id='4QEu3'></tfoot><dl id='4QEu3'><fieldset id='4QEu3'></fieldset></dl></div>

                        <tfoot id='4QEu3'></tfoot>
                        • <small id='4QEu3'></small><noframes id='4QEu3'>