UITableView does not scroll using UISearchBar

What I want to achieve is a UISearchBar that moves up and covers the UINavBar and contains the cancel button to the right of it. Everything is going fine until I use the following line of code:

searchDC = [[[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self] autorelease]; 

What happens, the UITableView just won't scroll, but everything else works as expected. If I delete this line, my navigation bar will be visible, and the search bar just sits below it, there will also be no cancel button.

Any ideas?

Code for drawing a search string:

 self.navigationItem.title = @"Search"; searchBar = [[[UISearchBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.view.bounds.size.width, 44.0f)] autorelease]; searchBar.autocorrectionType = UITextAutocorrectionTypeNo; searchBar.autocapitalizationType = UITextAutocapitalizationTypeNone; searchBar.keyboardType = UIKeyboardTypeAlphabet; searchBar.delegate = self; [searchBar becomeFirstResponder]; tableView.tableHeaderView = searchBar; tableView.tableHeaderView.frame = CGRectMake(0.f, 0.f, 480.f, 44.f); searchDC = [[[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self] autorelease]; searchDC.searchResultsDataSource = self; searchDC.searchResultsDelegate = self; searchDC.searchResultsTableView.separatorStyle = UITableViewCellSeparatorStyleNone; searchDC.searchResultsTableView.scrollEnabled = YES; overlayView.frame = CGRectMake(0, 50, 320, 480); [self.view addSubview:overlayView]; [self.view bringSubviewToFront:overlayView]; 
+4
source share
2 answers

There is not enough information to answer this question. You need to show the code of the UIViewController or UINavigation Controller (both .h and .m) where you configure the UISearchDisplayController.

EDIT:

You are implementing this completely wrong. Apple has a great example of how to implement this http://developer.apple.com/iphone/library/samplecode/TableSearch/Introduction/Intro.html

+1
source

From Apple documentation

Delegate for the search display controller (delegate), which responds to events such the starting or ending of a search, and the showing or hiding of the search interface.

Set delegate to UITableViewController

  searchDC.delegate = self; 

Also add a search searchBar to the tableView headerView

  [self.tableView setTableHeaderView:searchDC.searchBar]; 
0
source

Source: https://habr.com/ru/post/1314291/


All Articles