通过执行对数据集的搜索时UISearchBar
,搜索结果成功地在显示UITableViewController
的UITableView
。但是,当向下滚动结果时,UITableView
的行会明显显示在UINavigationBar
和仿真器的状态栏下方。
这显然不是我想要的外观。理想情况下,我希望UISearchBar
充当UITableView
的标头,所有搜索结果都包含在UISearchBar
范围按钮下方,但我的尝试未成功。
Below is the Storyboard setup of the relevant UITableViewController
and its UITableView
's properties.
Below is the relevant code that I am using to setup the UISearchController
and its UISearchBar
.
BallotTunesSearchTableViewController.h
@interface BallotTunesSearchTableViewController : UITableViewController <UISearchControllerDelegate, UISearchResultsUpdating, UISearchBarDelegate>
BallotTunesSearchTableViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
self.appDelegate = [[UIApplication sharedApplication] delegate];
// Initialize the search controller
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
self.searchController.dimsBackgroundDuringPresentation = NO;
// Setup the search bar
self.searchController.searchBar.delegate = self;
self.searchController.searchBar.scopeButtonTitles = [NSMutableArray arrayWithObjects:SongScopeName, ArtistScopeName, AlbumScopeName, nil];
self.tableView.tableHeaderView = self.searchController.searchBar;
}
Update: Note that the UITableViewController
is embedded in a UINavigationController
, and when setting the translucence of the UINavigationBar
to NO
, the UISearchBar
slides off the view along with the UINavigationBar
.
Also note that I am not implementing the UISearchBar
in Storyboard (however, I may take that route if I can't get my current setup to work).
After several face palms, it all came down to the lack of this line of code:
self.definesPresentationContext = YES;
将表示上下文设置为YES
指示当视图控制器显示时应覆盖视图控制器的视图UISearchController
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句