什么阻止UITableView索引出现?(What prevents the UITableView index from appearing?)

编程入门 行业动态 更新时间:2024-10-25 06:24:20
什么阻止UITableView索引出现?(What prevents the UITableView index from appearing?)

我有一个UITableView,其SearchBar具有可见的ScopeBar。 我已经实现了所有必需的委托和数据源方法来支持表索引。 然而,当显示表格视图时,没有显示部分索引。 显示搜索结果表时,会显示部分指示。

我从这个答案中实现了代码片段,并确认主表实际上是索引的。

我真的很难过。 记录表明一切都已到位,以便有这项工作,但我不能为我的生活弄清楚为什么主表不显示索引。 是的,主表的索引是设置的; 我可以在记录中看到它们。

对于主表,我可以看到请求并返回索引标题,但不显示。

对于搜索结果表,将显示相同的日志记录(请求并返回标题),并显示它们。

有一点需要注意,虽然我看不出这会导致表中的索引不出现,但是SearchBar类实际上是一个简单地覆盖setShowsScopeBar:的子类setShowsScopeBar:强制它为YES。 我尝试使用和不使用此覆盖的应用程序。 相同的结果:主表视图中没有索引。

所以问题是:什么会阻止索引显示,即使支持索引的所有必需的委托和数据源方法都已到位(并且至少在搜索结果表中工作,因为调用了方法并显示了索引对于那个观点。)

谢谢!

I have a UITableView, with a SearchBar that has a visible ScopeBar. I have implemented all the requisite delegate and data source methods to support table indices. Yet, when the table view is shown, there are no section indices displayed. When the search results table is shown, there are section indicies displayed.

I implemented the code snippet from this answer and confirmed that the main table is, in fact, indexed.

I am really stumped. Logging suggests that everything is in place to have this work, but I cannot for the life of me figure out why the main table doesn't show indices. And yes, the indices for the main table are setup; I can see them in my logging.

For the main table, I can see that the index titles are requested and returned, but not displayed.

For the search results table, the same logging appears (titles are requested and returned), and they ARE displayed.

One thing to note, although I can't see how this would cause the indices in the table not to appear, is that the SearchBar class is actually a subclass that simply overrides setShowsScopeBar: to force it to YES. I tried my app with and without this override. Same result: no index in the main table view.

So the question is: What would prevent the index from showing, even when all the requisite delegate and data source methods for supporting indices is in place (and working at least for the search results table, because the methods are called and the index is shown for that view.)

Thanks!

最满意答案

所以这几个月之后,这是解决这个问题的方法。

首先,看起来iOS 4.3 SDK中的-reloadSectionIndexTitles似乎在(重新)在视图中显示部分索引标题方面似乎没有做任何事情。 我仍然必须使用-reloadData ,这是不幸的,但最后还是可以的。 (没有尝试任何较新的iOS版本,FWIW ......)

现在,最初的问题是索引标题被挤进屏幕右边缘的上半部分,好像键盘正在显示。 但没有键盘显示!

所以我开始思考:键盘显示的原因是什么? 第一响应者会标记出通常会导致键盘显示的东西! (或者,其他东西错误地指示键盘正在显示。)在我看来,唯一能做到这一点的是搜索栏。

这是情节变浓的地方。 我的搜索栏有一个范围栏,我希望它始终可见。 这是非标准的。 所以要做到这一点,我将UISearchBar分类并覆盖-searchBar:setShowsScopeBar: ::

- (void) setShowsScopeBar:(BOOL) show { [super setShowsScopeBar: YES]; // always show! [self resignFirstResponder]; }

我的初始实现不包括对resignFirstResponder的调用。 因此,每当在我的UISearchBar实例上调用此方法时(只是告诉超类将范围栏设置为可见),搜索栏(或可能是范围栏)被标记为第一响应者但未显示键盘。 反过来,正如我所知道的那样,当表视图显示部分索引标题时,它认为某些东西是第一响应者并呈现了一个压扁的索引。 表视图方面的错误假设进一步证明了表格的lat行允许在屏幕中间向上滚动 - 就像键盘正在显示一样!

添加对resignFirstResonder的调用通过清除错误设置的任何状态以指示(某处)键盘正在显示来解决了该问题。 现在,索引按预期显示在全屏高度。

非常。 离奇。

我花了很多时间搞清楚这一点。 也许这种行为是我的实现的副产品,这无疑是非标准的(范围栏更像是UISegmentedControl的3个选项中的2个)。 无论如何,在我将调用添加到resignFirstResponder之前的行为至少是意外的。

我想我会把这个决议发布给任何可能在未来偶然发现的人。 希望能帮助到你。

So after all these months, here's the solution to this problem.

First off, it would appear that -reloadSectionIndexTitles in iOS 4.3 SDK still does not seem to do anything with respect to (re)displaying the section index titles in the view. I still have to use -reloadData, which is unfortunate, but in the end it's ok. (Have not tried under any newer iOS versions, FWIW...)

Now, the original problem was that the index titles appeared squeezed into the top half of the right edge of the screen, as if a keyboard were showing. But no keyboard was showing!

So I got to thinking: What makes a keyboard show? Something is marked at first responder that would normally cause a keyboard to show! (Or, something else is erroneously indicating that a keyboard is showing.) The only thing in my view that would do that is the search bar.

Here's where the plot thickens. My search bar has a scope bar, which I wanted to be visible always. This is non-standard. So to do that, I sub-classed UISearchBar and overrode -searchBar:setShowsScopeBar::

- (void) setShowsScopeBar:(BOOL) show { [super setShowsScopeBar: YES]; // always show! [self resignFirstResponder]; }

My initial implementation did NOT include the call to resignFirstResponder. So, whenever this method was called on my UISearchBarinstance (simply telling the superclass to set the scope bar visible), the search bar (or perhaps the scope bar) was being marked first responder but not showing a keyboard. This in turn, as best I can tell, was having the effect that when it came time for the table view to display the section index titles, it believed something was first responder and presented a squished index. This erroneous assumption on the part of the table view was further evidenced by the fact that the lat row of the table was allowed to scroll up just above mid screen -- as if a keyboard were showing!

Adding the call to resignFirstResonder solved the issue by clearing whatever state was set erroneously to indicate (somewhere) that a keyboard was showing. Now the index appears at full screen height, as expected.

Very. Bizarre.

I spent a lot of time figuring this out. Perhaps this behavior is a by-product of my implementation which is admittedly non-standard (the scope bar acts more like a UISegmentedControl for 2 of its 3 choices). In any event, the behavior before I added the call to resignFirstResponder was at a minimum unexpected.

I thought I'd post the resolution for anyone who might stumble upon this in the future. Hope it helps.

更多推荐

本文发布于:2023-07-30 23:47:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1340317.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:索引   UITableView   prevents   appearing   index

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!