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];
source share