Hide UISearchBar UISearchDisplayController

I have a tab-based application and a UInavigationcontroller for each tab. In TabViewController I implemented UIsegmentedcontrol , searchDisplayController and searchDisplayController . Elements navigationItems, tabledata change depending on the choice of segmentation. And for the segment, I hid the search bar. But when the search bar is hidden, the first row of the table does not respond to didselectrowatindexpath .

Here is my code

Segment Change In Action

 - (void)indexDidChangeForSegmentedControl:(UISegmentedControl *)aSegmentedControl { [self changeNavigationItems]; l.text = [NSString stringWithFormat:@"%d",self.segmentControl.selectedSegmentIndex]; if([segmentIndexesToHideSearchBar containsObject: [NSString stringWithFormat:@"%d", self.segmentControl.selectedSegmentIndex]]) { self.searchDisplayController.searchBar.hidden = YES; self.dataTable.frame = CGRectMake(0, 0, self.dataTable.frame.size.width, self.dataTable.frame.size.height); } else { self.searchDisplayController.searchBar.hidden = NO; self.dataTable.frame = CGRectMake(0, 44, self.dataTable.frame.size.width, self.dataTable.frame.size.height); } [self.dataTable reloadData]; 

}

Other codes are common, others work correctly.

The second problem is when I return from the details view by clicking on a row, changing the table frame is not saved. There is a space in which there was a search bar.

Waiting for help.

+4
source share
2 answers

I understood that. My first problem was that the first click on a table row did not respond. This was for me to make didSelectRowAtIndexPath wrong for didDeselectRowAtIndexPath . What a stupid mistake, and I suffered for hours ... :(

The second problem was that I wrote the code for changing and changing frames in the viewDidLoad function, I moved the code to the viewDidAppear function. Now the codes work correctly.

+1
source

I think this is not the right approach, but it works for me :) to hide it:

 CGRect searchFrame = self.searchDisplayController.searchBar.frame; searchFrame.size.height = 0; self.searchDisplayController.searchBar.frame = searchFrame; self.searchDisplayController.searchBar.hidden = YES; 

To open it again:

 searchFrame.size.height = 44; self.searchDisplayController.searchBar.frame = searchFrame; self.searchDisplayController.searchBar.hidden = NO; 

I'm not sure if this works with autorun, and have never tried it. (Also this is on Xcode <5, iOS <7)

+6
source

All Articles