【发布时间】:2017-07-07 20:57:51
【问题描述】:
在展示搜索控制器时,我将 showScopeBar 属性设置为隐藏或显示范围栏
- (void)willPresentSearchController:(UISearchController *)searchController {
// do something before the search controller is presented
NSMutableArray *scopeArray = @[@"All"].mutableCopy;
UISearchBar *searchBar =_searchController.searchBar;
if (![labelDepartmentSelection.text isEqualToString:@"Department"]) {
[scopeArray addObject:@"Department"];
}
if (![labelJobSelection.text isEqualToString:@"Job"]) {
[scopeArray addObject:@"Job"];
}
searchBar.scopeButtonTitles = scopeArray;
searchBar.showsScopeBar = scopeArray.count>1;
[searchBar layoutIfNeeded];
NSArray *subviews = searchBar.subviews;
if([[UIDevice currentDevice].systemVersion floatValue]>=7.0) {
//Get search bar with scope bar to reappear after search keyboard is dismissed
UIView *scopeBar = [subviews.firstObject subviews].firstObject;
[scopeBar setHidden:NO];
CGRect frame = scopeBar.frame;
frame.origin.y = frame.origin.y = 64.0;
scopeBar.frame = frame;
}
[searchBar layoutSubviews];
[searchBar sizeToFit];
[serviceOptionTableView setContentInset:UIEdgeInsetsMake(scopeArray.count>1?44:0, 0, 0, 0)];
serviceOptionTableView.tableHeaderView = searchController.searchBar;
}
当我只是根据范围标题隐藏和显示范围栏时,我希望它扭曲 这是这种情况
- (void)willPresentSearchController:(UISearchController *)searchController {
// do something before the search controller is presented
NSMutableArray *scopeArray = @\[@"All"\].mutableCopy;
UISearchBar *searchBar =_searchController.searchBar;
if (!\[labelDepartmentSelection.text isEqualToString:@"Department"\]) {
\[scopeArray addObject:@"Department"\];
}
if (!\[labelJobSelection.text isEqualToString:@"Job"\]) {
\[scopeArray addObject:@"Job"\];
}
searchBar.scopeButtonTitles = scopeArray;
searchBar.showsScopeBar = scopeArray.count>1;
\[serviceOptionTableView setContentInset:UIEdgeInsetsMake(scopeArray.count>1?44:0, 0, 0, 0)\];
}
这是案例2的图片
【问题讨论】:
-
你能解决这个问题吗?
-
实际上我发现在运行时更新 uisearch bar 的范围会造成这个问题..
标签: objective-c uitableview uisearchbar uisegmentedcontrol uisearchcontroller