ios - UISearchBar 在向下滚动之前不可见

标签 ios objective-c uitableview uisearchbar uirefreshcontrol

我以编程方式向我的 tableHeaderView 添加了一个 UISearchBar,但它没有在 View 加载时显示。 我的表格内容上方只有一个空白区域。当我向下滚动一点时,它出现了。 我更改了 tableHeaderView 的背景颜色以查看它是否可见 - 我可以看到更改后的颜色,因此 searchBar 本身似乎是不可见的。 有什么想法吗?

这是我的代码:

- (void)viewDidLoad
{
[super viewDidLoad];
...
// Initialize the refresh control.
[self.refreshControl addTarget:self
                        action:@selector(refreshData)
              forControlEvents:UIControlEventValueChanged];
// Suchelemente erzeugen
self.searchBar = [UISearchBar new];
self.searchDC = [[UISearchDisplayController alloc] initWithSearchBar:self.searchBar contentsController:self];
self.searchDC.searchResultsDelegate = self;
self.searchDC.delegate = self;
self.searchDC.searchResultsDataSource = self;
self.tableView.tableHeaderView = self.searchBar;
// some attempts to make it visible
self.searchBar.hidden = NO;
self.searchBar.layer.hidden = NO;
[self.searchBar sizeToFit];
}

好的,发现问题出在刷新控件上。 在 viewWillAppear 中调用了一个方法来更新刷新控件的标题。当我评论这一行时,搜索栏出现:

self.refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:title];

那么,如何让它们同时工作呢??

最佳答案

您可以通过以下方式设置它:

self.navigationItem.hidesSearchBarWhenScrolling = NO;

关于ios - UISearchBar 在向下滚动之前不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28126596/

相关文章:

ios - 通知画外音用户他们已突出显示容器中的元素

iphone - UITableView 中的 UITextFields,输入的值重新出现在其他单元格中

ios - 带有 CALayer 的 UILabel 阴影不绘制

ios - 将 UIButton 保持在 viewController 的底部和 TableView 的前面

ios - UITableView 滚动时滞后,每个单元格包含 4 个 UIButtons 和 4 个 UILables

iphone - AVAudioPlayer 不加载声音

iphone - Siri SDK 可用吗?

ios - iOS 上的 Metal 是否支持 SIMD 组?

objective-c - videoMinFrameDuration 已弃用

ios - 如何更改 UITableView 中选定单元格的颜色?