Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pull-To-Refresh and search bar

Tags:

ios

I'm wondering what solution is the best for the pull down action: Pull-To-Refresh vs. Pull-To-Search? What if I want to have both (search bar and refresh) like in the Mail app? Don't know what the approval in the app store does look like ...

How would you implement that with a UITableViewController?

like image 905
grabner Avatar asked Aug 07 '14 22:08

grabner


1 Answers

You can have both Pull-To-Refresh and Pull-To-Search in a UITableViewController quite easily.

Here's Pull to Refresh:

UIRefreshControl *refresh = [[UIRefreshControl alloc] init];
[self.tableView addSubview:refresh];
self.refreshControl = refresh;

To know when it has been 'pulled', add a target to the control:

[self.refreshControl addTarget:self action:@selector(refreshContent:) forControlEvents:UIControlEventValueChanged];

Here's "Pull-To-Search":

UISearchBar *searchBar = [[UISearchBar alloc] init];
UISearchDisplayController *searchController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
searchController.delegate = self;
searchController.searchResultsDataSource = self;
self.tableView.tableHeaderView = searchBar;
self.tableView.contentOffset = CGPointMake(0, CGRectGetHeight(searchBar.frame));

As you can see, Pull-To-Search is really just adding the searchBar as the tableHeaderView and offsetting the tableView a bit initially so the search bar isn't shown initially. That doesn't interfere with Pull-To-Refresh at all!

like image 55
Acey Avatar answered Sep 20 '22 14:09

Acey