UITableView contentOffSet无法正常工作 [英] UITableView contentOffSet is not working properly

查看:96
本文介绍了UITableView contentOffSet无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

viewWillAppear 中,我添加了 UISearchBar 作为 UITableView 。当视图加载时,我使用 UITableView 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆