【发布时间】:2016-06-14 12:30:19
【问题描述】:
在我的 iOS 应用程序中有两个视图。在第一个视图中有一个按钮。当用户按下按钮时,它导航到带有搜索栏的第二个视图控制器。在该视图控制器中,用户必须点击搜索器以获取键盘。我想要的是点击搜索器,并在视图出现时自动弹出键盘给用户而不做任何事情。
我尝试了以下,
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.fromportSearchcontroller setActive:YES];
[self.fromportSearchcontroller.searchBar becomeFirstResponder];
}
但这没有用。希望您对此有所帮助。
注意:
这就是我创建uisearchcontroller
- (void)settinguptheSearchBarforfromairports
{
self.fromportSearchcontroller = [[UISearchController alloc] initWithSearchResultsController:nil];
self.fromportSearchcontroller.searchResultsUpdater = self;
self.fromportSearchcontroller.searchBar.delegate = self;
self.definesPresentationContext = YES;
self.fromaiportsTableView.tableHeaderView = self.fromportSearchcontroller.searchBar;
self.fromportSearchcontroller.searchBar.barTintColor = [UIColor lightGrayColor];
self.fromportSearchcontroller.dimsBackgroundDuringPresentation = NO;
//self.fromportSearchcontroller.active = YES;
//self.fromportSearchcontroller.searchBar.text = @"type city or airport";
[self.fromportSearchcontroller.searchBar sizeToFit];
}
我在 'ViewDidLoad' 方法中调用了这个方法。
- 搜索栏已激活,但键盘未自动出现(弹出)。
【问题讨论】:
-
self.fromportSearchcontroller.searchBar为零吗? -
@Larme,我更新了问题
-
很确定这是在此处复制(并已解决):stackoverflow.com/questions/27951965/…
标签: ios objective-c uisearchbar uikeyboard