简体   繁体   English

UITableView在某些情况下不会滚动

[英]UITableView Won't Scroll In Certain Conditions

My app has a set of categories. 我的应用程序具有一组类别。 A category can have sub-categories. 类别可以包含子类别。

DirectoryCategoryController is the first screen, displaying all the top-level categories. DirectoryCategoryController是第一个屏幕,显示所有顶级类别。 Works great. 效果很好。 When you tap a cell, if the category selected has sub-categories, I instantiate a new instance of DirectoryCategoryController and push it to display the sub-categories. 当您点击一个单元格时,如果所选类别具有子类别,则我将实例化DirectoryCategoryController的新实例并将其推送以显示子类别。 From there, you tap a sub-category and see the contents. 从那里,您点击一个子类别并查看其内容。

The problem is that while the top level works fine, when I tap in and see the sub-categories, the table view won't scroll. 问题是,尽管顶层工作正常,但是当我点击并查看子类别时,表格视图将不会滚动。 The search bar takes touches, the table cells take touches but up and down scrolling does not work, like the table view is vertically frozen in space. 搜索栏进行触摸,表格单元进行触摸,但是上下滚动不起作用,就像表格视图在空间上垂直冻结一样。

If I tap the search bar and hit cancel or if I go into a sub-categories contents and then hit back, the very same table view that didn't scroll works just fine. 如果点击搜索栏并单击“取消”,或者进入子类别的内容然后单击“返回”,则没有滚动的完全相同的表格视图就可以正常工作。

Also, if the table view has more items than fit on the screen (about anything bigger than 8 in this layout), everything works. 此外,如果表格视图中的项目超出了屏幕显示的大小(此布局中的任何内容大于8),则一切正常。

Very odd problem ; 非常奇怪的问题; kinda blowing my mind. 有点让我震惊。 Any insight? 有见识吗?

So, I figured this out and thought I would answer as a reference. 因此,我想出了这一点,并认为我将作参考。

At this point, I think it may be an iPhone OS bug and I'm filing a RADAR. 在这一点上,我认为这可能是iPhone OS的错误,我正在提交RADAR。

A UIScrollView, of which UITableView is a subclass, will not attempt to scroll if everything fits on one screen. 如果所有内容都适合一个屏幕,则UITableView是其子类的UIScrollView将不会尝试滚动。

In my case, it appears the scroll view thought everything fit (it was very close) but it didn't. 以我为例,滚动视图似乎认为一切都适合(非常接近),但事实并非如此。 Actually, if you removed the UISearchBar from the UITableView, everything would have fit and it wouldn't need to scroll. 实际上,如果您从UITableView中删除了UISearchBar,那么所有内容都将适合并且不需要滚动。 My guess is that it's incorrectly determining the geometry when the UISearchBar is attached. 我的猜测是,在附加UISearchBar时,它错误地确定了几何形状。

Anyway, the work-around was to add this: [self.tableView setAlwaysBounceVertical:YES]; 无论如何,解决方法是添加以下内容:[self.tableView setAlwaysBounceVertical:YES];

The odd thing was that when another view was pushed and then popped, the vertical bounce worked fine, furthering my suspicions it's an iPhone bug. 奇怪的是,当另一个视图被推开然后弹出时,垂直弹起效果很好,这使我进一步怀疑这是一个iPhone错误。

I noticed the same thing when using A UITableView with a UISearchBar as the header view, as configured in Interface Builder in Xcode 4.3.1. 当在Xcode 4.3.1中的Interface Builder中配置UITableViewUISearchBar作为标题视图时,我注意到了同一件事。 In my viewDidLoadMethod , I added the following code and it fixed the problem for me: 在我的viewDidLoadMethod ,添加了以下代码,它为我解决了这个问题:

self.contactsTable.bounces = YES;

I believe that it's a bug that disables the bounces property, but it can be fixed by re-enabling it. 我相信这是一个禁用bounces属性的错误,但是可以通过重新启用它来解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM