【发布时间】:2018-05-11 22:27:39
【问题描述】:
我正在使用 UISearchController 创建一个搜索屏幕,我必须在其中显示三个范围按钮。我以编程方式放置了搜索栏。但不知何故,范围按钮隐藏在 UITableView 后面。
- (void)viewDidLoad {
[super viewDidLoad];
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.searchBar.delegate = self;
self.tblFoundList.tableHeaderView = self.searchController.searchBar;
self.definesPresentationContext = YES;
[[UITextField appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]] setDefaultTextAttributes:@{NSForegroundColorAttributeName: [UIColor blackColor]}];
[[UITextField appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]] setAttributedPlaceholder:[[NSAttributedString alloc] initWithString:@"Search by" attributes:@{NSForegroundColorAttributeName: [UIColor lightGrayColor]}]];
self.searchController.searchBar.tintColor = [UIColor purpleColor];
self.searchController.searchBar.barTintColor = [UIColor groupTableViewBackgroundColor];
self.searchController.searchBar.scopeButtonTitles = @[@"A",@"B", @"C"];
[self.searchController.searchBar sizeToFit];
}
有人可以帮忙吗?谢谢。
【问题讨论】:
-
你在使用自动布局吗?
-
@iPeter 我以编程方式放置,没有自动布局。
-
那么请检查你的
tableview和buttons的框架。根据屏幕截图,您的tableview的y position似乎不正确。 -
尝试给出 tableHeaderView 的高度,你在哪个操作系统中检查这个? iOS11 提供了可能导致此问题的默认标题高度。更改表头高度应该可以工作。
-
@iPeter,我尝试更改我创建的 TableView 的 y 位置,但它没有显示任何结果。不过谢谢你的帮助
标签: ios uitableview uisearchcontroller iphone-8-plus