【发布时间】:2015-06-12 21:24:18
【问题描述】:
我有一个适用于 iOS8 的 iPhone 应用程序。 UIPageViewController 有一个 UITableViewController 的子视图,这就是我放置 UISearchController 的地方。
当 UITableViewController 第一次出现时,我可以通过这样做来激活搜索
[self.searchController.searchBar becomeFirstResponder];
但是,一旦视图控制器通过推送到另一个表视图控制器或模态显示 UIViewController(视觉上屏蔽它)变得不可见,searchBar 在它重新出现后就不能再成为第一响应者。
搜索本身可以通过
[self.searchController setActive:YES];
但是,以这种方式没有插入符号闪烁(用户必须在 searchBar 内点击才能开始输入)。
我有几乎相同的 UITableViewController 和 UISearchController 没有事件。所以,我一定是遗漏了一些东西,但我想请你对我应该注意解决这个问题的方向提出意见。
下面是我如何设置搜索控制器。
@interface MonthTableViewController () <UISearchResultsUpdating, UISearchControllerDelegate>
@property (nonatomic, strong) UISearchController *searchController;
UITableViewController *searchController = [[UITableViewController alloc]initWithStyle:UITableViewStylePlain];
searchController.tableView.dataSource = self;
searchController.tableView.delegate = self;
self.searchController = [[UISearchController alloc] initWithSearchResultsController:searchController];
self.searchController.searchResultsUpdater = self;
self.searchController.delegate = self;
self.searchController.searchBar.frame = CGRectMake(self.searchController.searchBar.frame.origin.x, self.searchController.searchBar.frame.origin.y, self.searchController.searchBar.frame.size.width, 44.0);
self.tableView.tableHeaderView = self.searchController.searchBar;
self.definesPresentationContext = YES;
// Hide search bar
CGRect myBounds = self.tableView.bounds;
myBounds.origin.y += self.searchController.searchBar.frame.size.height;
_lastlyAddedTableBoundY = self.searchController.searchBar.frame.size.height;
self.tableView.bounds = myBounds;
【问题讨论】:
标签: xcode uisearchbar becomefirstresponder