UITableView contentOffSet无法正常工作 [英] UITableView contentOffSet is not working properly
问题描述
在 viewWillAppear
中,我添加了 UISearchBar
作为 UITableView $的标题视图C $ C>。当视图加载时,我使用
UITableView $ c $的contentOffSet在
UINavigationBar
下隐藏 UISearchbar
C>。当用户下拉tableview时,会显示搜索栏。
In viewWillAppear
, I have added UISearchBar
as my headerview of UITableView
. When view loads, I hides UISearchbar
under UINavigationBar
using contentOffSet of UITableView
. When user pull down the tableview the searchbar gets displayed.
添加headerview后,我使用下面的代码隐藏它。
After adding headerview I hides it using below code.
self.tableView.contentOffset = CGPointMake(0, 40); //My searhbar height is 40
但有时 contentOffSet
没有隐藏headerview。可能是什么错误。
But at times contentOffSet
is not hiding headerview. What can be the mistake.
推荐答案
这对我有用:
// contentOffset will not change before the main runloop ends without queueing it, for iPad that is
dispatch_async(dispatch_get_main_queue(), ^{
// The search bar is hidden when the view becomes visible the first time
self.tableView.contentOffset = CGPointMake(0, CGRectGetHeight(self.searchBar.bounds));
});
将它放在你的-viewDidLoad或-viewWillAppear
Put it in your -viewDidLoad or -viewWillAppear
这篇关于UITableView contentOffSet无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!