隐藏UISearchDisplayController的UISearchBar
我有一个基于tabbar的应用程序,并为每个选项卡提供UInavigationcontroller
。 在TabViewController
,我实现了一个UIsegmentedcontrol
, searchDisplayController
和uitableview。 navigationItems,tabledata基于segmentedcontrol选择进行更改。 对于一个片段,我隐藏了搜索栏。 但是当隐藏didselectrowatindexpath
,tableview第一行不响应didselectrowatindexpath
。
这是我的代码,
在细分变更行动中
- (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];
}
其他代码是通用的,其他代码正常。
第二个问题是当我通过点击一行从详细信息视图返回时,不保留表格框架的更改。 搜索栏有一个空间。
等待帮助。
我想这不是正确的方法,但它适用于我:)让它隐藏:
CGRect searchFrame = self.searchDisplayController.searchBar.frame; searchFrame.size.height = 0; self.searchDisplayController.searchBar.frame = searchFrame; self.searchDisplayController.searchBar.hidden = YES;
再次“揭示”它:
searchFrame.size.height = 44; self.searchDisplayController.searchBar.frame = searchFrame; self.searchDisplayController.searchBar.hidden = NO;
我不确定这是否适用于autolayout,从未尝试过。 (这也是Xcode <5,iOS <7)
我已经想到了。 我的第一个问题是第一次点击tableview行没有回应。 那是因为我错误地将didSelectRowAtIndexPath
用于didDeselectRowAtIndexPath
。 真是个愚蠢的错误,我忍受了几个小时…… 🙁
第二个问题是因为我在viewDidLoad
函数中编写了隐藏和帧更改代码,我将代码移动到viewDidAppear
函数。 现在代码工作正常。