当内容适合屏幕时,如何在UITableView表中禁用滚动 [英] How to disable scrolling in UITableView table when the content fits on the screen

查看:139
本文介绍了当内容适合屏幕时,如何在UITableView表中禁用滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的iphone应用程序中有一些(分组样式)表格(仅在屏幕的一部分上添加 Interface Builder ,但不是<$ c $的子类) c> UITableViewController )80%的时间都很小并且适合屏幕。当桌子适合屏幕时,我想禁用滚动,使其更清洁。但如果表格离开屏幕(稍后将行添加到行中),我想再次启用滚动(因为否则您无法看到该内容。)

I have a few (grouped style) tables in my iphone app (only on part of the screen and added with Interface Builder though, not subclassed from UITableViewController) that 80% of the time are small and will fit on the screen. When the table fits on the screen, I'd like to disable scrolling, to make it a bit cleaner. But if the table goes off the screen (when rows are later added to it), I'd like to enable scrolling again (because otherwise you can't see that content.)

有办法做到这一点吗?我似乎无法弄明白。我知道这样做:

Is there a way to do this? I can't seem to figure it out. I do know to do:

tableView.scrollEnabled = NO;

但我不知道在哪里,或者我是否必须计算表格对象的大小让这个工作。

but I'm not sure where, or if I have to calculate the table object size or something to get this to work.



更新
以下是最终对我有用的解决方案:


Update: Here's the solution that finally worked for me:

if (table.contentSize.height < table.frame.size.height) {
   table.scrollEnabled = NO;
 }
else {
   table.scrollEnabled = YES;
 }

我在调用 reloadData 在桌面上,它计算出正确的尺寸并且似乎有效。

I run this code after calling reloadData on the table, and it calculates the right sizes and appears to work.

table.frame.size.height 是屏幕上显示的对象的实际大小(您可以在 Interface Builder 中看到),而 table.contentSize.height 的高度是:标题,页脚和每个单元格的高度加在一起。

table.frame.size.height is the actual size of the object (you can see this in Interface Builder) displayed on the screen, whereas table.contentSize.height is the heights of: the header, the footer, and the height of every cell added together.

推荐答案

我想你要设置

tableView.alwaysBounceVertical = NO;

这篇关于当内容适合屏幕时,如何在UITableView表中禁用滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆