0

我正在将动态滚动的 UISearchBar 添加到 tableview 的顶部。为此,我将 UISearchBar 添加为 tableview 的子视图,然后实现了一个 scrollviewdelegate 方法,以便搜索栏始终固定在顶部。我还相应地设置了 tableView 的 contentInset,以便最上面的单元格偏移到足以用于搜索栏。

我遇到的唯一问题是在表格视图中的第一个单元格上方绘制的默认分隔符。当从顶部开始向下滚动时,分隔符实际上绘制在搜索栏上方,而不是下方。这会产生一个我想修复的可怕的用户界面错误。请注意,这只发生在第一个单元格上;单元格之间的每个其他分隔符都会在搜索栏下滚动,这是应该的,并且没有相同的 UI 错误。有什么想法吗?

在此处输入图像描述

4

1 回答 1

1

Are you certain that the UISearchBar is frontmost? Try bringing it all the way to the front in code, in your viewDidLoad. If that doesn't work to solve the glitch, consider an alternative solution to your interface. Here are some - try any one of them:

  • Make the UISearchBar the header for the UITableView (not a section; the table view itself). This is very standard interface.

  • If you are on iOS 6, instead of the scroll view delegate trick (which was quite standard before iOS 6, well done), use constraints to pin the search bar to a view higher up the view hierarchy than the table view. (Since you are in a navigation controller, that would be the navigation controller's view in your case.) That's the new iOS 6 way to prevent a scroll view subview from being scrolled with the content. I do not know if that will solve the glitch but it could be worth a try.

  • Don't use the default separator. It is not difficult to draw your own separator as part of the cell background image.

于 2012-12-01T18:18:40.127 回答