UIRefreshControl behaves differently after adding UISearchBar

I'm using a UITableViewController subclass in iOS 7.

Before I added the search bar as the table view's tableHearerView, the UIRefreshControl worked as I expected: I triggered beginRefreshing in viewDidLoad and I could see it spinning every time I entered this screen.

After I added the search bar, I can't see UIRefreshControl spinning when I enter this screen. Everything else seems to work fine, eg pulling down will show the spinning UIRefreshControl.

Did I use the 2 widgets in right way? How to fix this issue so I can see the spinning like what I saw before adding the search bar?

Thanks a lot in advance!


It looks like if you invoke the beginRefreshing method manually you also need to set the offset of the tableView manually.

Here is the solution in Objective-C:

[self.tableView setContentOffset:CGPointMake(0, -self.refreshControl.frame.size.height) animated:YES];

and here the solution in Swift:

self.tableView.setContentOffset(CGPointMake(0, -self.refreshControl!.frame.size.height), animated:true)
链接地址: http://www.djcxy.com/p/75416.html

上一篇: 你如何改变UIRefreshControl的beginRefresh高度?

下一篇: 添加UISearchBar后,UIRefreshControl的行为会有所不同