使用以下代码,示波器栏不可见(按钮工作但不可见 - 只是黑色空间)
UISearchBar* searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 44 + (_showScope?40:0));];
searchBar.barStyle = UIBarStyleBlack;
searchBar.scopeButtonTitles = [NSArray arrayWithObjects:@"string1", @"string2", nil];
searchBar.showsScopeBar = YES;
searchBar.delegate = self;
self.tableView.tableHeaderView = searchBar;
在iOS6中运行良好。有什么想法吗?
答案 0 :(得分:2)
这似乎是一种解决方法:
UISearchBar* searchBar = [[UISearchBar alloc] initWithFrame:CGRectZero];
searchBar.barStyle = UIBarStyleBlack;
searchBar.scopeButtonTitles = [NSArray arrayWithObjects:@"string1", @"string2", nil];
searchBar.showsScopeBar = YES;
searchBar.delegate = self;
self.tableView.tableHeaderView = searchBar;
searchBar.frame = CGRectMake(0, 0, self.tableView.frame.size.width, 44 + (_showScope?40:0));
不错!
答案 1 :(得分:1)
感谢Nick H247让我走上正轨。但是,他的解决方法为我提出了另一个问题,搜索结果列表显示在搜索栏后面,这样我就无法从列表的开头选择搜索结果。我通过在将UISearchBar分配给tableHeaderView之前设置框架来修复此问题。
UISearchBar* searchBar = [[UISearchBar alloc] initWithFrame:CGRectZero];
searchBar.barStyle = UIBarStyleBlack;
searchBar.scopeButtonTitles = [NSArray arrayWithObjects:@"string1", @"string2", nil];
searchBar.showsScopeBar = YES;
searchBar.delegate = self;
searchBar.frame = CGRectMake(0, 0, self.tableView.frame.size.width, 44 + (_showScope?40:0));
self.tableView.tableHeaderView = searchBar;
答案 2 :(得分:0)
简单,调用searchBar.sizeToFit;