4
votes

I have a tabbar based application, and UInavigationcontroller for every tab. In a TabViewController, I have implemented a UIsegmentedcontrol, searchDisplayController and uitableview. The navigationItems, tabledata are changed based on the segmentedcontrol select. And for a segment i have hidden the search bar. But when the searchbar is hidden, tableview first row does not respond to didselectrowatindexpath.

Here is my code,

In segment change 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 generic and other things are working correct.

Second problem is when i am getting back from a details view by clicking on a row, the change of frame of table is not kept. There is a space where searchbar was.

Waiting for help.

2

2 Answers

6
votes

I guess this is not the correct approach, but it works for me :) to make it hidden:

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

self.searchDisplayController.searchBar.frame = searchFrame;
self.searchDisplayController.searchBar.hidden = YES;

To "reveal" it again:

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

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

1
votes

I have figured that out. My first problem was the first click on tableview row did not respond. That was for i have mistaken didSelectRowAtIndexPath for didDeselectRowAtIndexPath. What a silly mistake and I suffered for hours...:(

The second problem was for I was writing the hiding and frame changing code in viewDidLoad function, I moved the code to viewDidAppear function. Now the codes are working properly.