То, что вы видите, представляет собой особое поведение UITableView
, когда для tableHeaderView
задан экземпляр UISearchBar
. Я считаю, что это поведение жестко закодировано. Таким образом, чтобы получить его для собственного взгляда, вам нужно расширить UISearchBar
. Или, что еще лучше, создайте такой скрывающий заголовок один раз и оберните в него свои заголовки, когда вам нужно скрытое поведение:
@interface HidingTableViewHeader : UISearchBar
- (id)initWithHeader:(UIView *)header;
@end
@implementation HidingTableViewHeader
- (id)initWithHeader:(UIView *)header
{
// We don't really care about the search bar initialization
self = [super init];
if (self) {
// Remove all the sub-views that make up the search bar UI
[self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
// Override UISearchBar's fixed size
self.size = header.size;
// Match the tableHeaderView behavior: auto-resize horizontally
header.autoresizingMask = UIViewAutoresizingFlexibleWidth;
// Make the header the only sub-view
[self addSubview:header];
}
return self;
}
@end
Используйте это так:
self.tableView.tableHeaderView = [[HidingTableViewHeader alloc] initWithHeader:someRegularView];