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

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

问题描述

我的 iphone 应用程序中有一些(分组样式)表(仅在屏幕的一部分上并添加了 Interface Builder,但不是从 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天全站免登陆