ios – 使UISearchController搜索栏自动激活

ios – 使UISearchController搜索栏自动激活,第1张

概述我已经在navigatiom栏中实现了一个带有搜索栏的UISearchController,我想在加载视图时使搜索栏处于活动状态.当我说活动时,我的意思是键盘出现,用户可以键入他/她的搜索而不点击搜索栏. 我使用以下代码初始化了UISearchController: - (void)viewDidLoad{ self.searchController = [[UISearchContro 我已经在navigatiom栏中实现了一个带有搜索栏的UISearchController,我想在加载视图时使搜索栏处于活动状态.当我说活动时,我的意思是键盘出现,用户可以键入他/她的搜索而不点击搜索栏.

我使用以下代码初始化了UISearchController:

- (voID)vIEwDIDLoad{    self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];    [self.searchController setSearchResultsUpdater:self];    [self.searchController setDimsBackgroundDuringPresentation:NO];    [self.searchController setHIDesNavigationbarDuringPresentation:NO];    [self.navigationItem setTitleVIEw:self.searchController.searchbar];    [self setdefinesPresentationContext:YES];    [self.searchController.searchbar setDelegate:self];    [self.searchController.searchbar setShowsCancelbutton:YES];    [self.searchController.searchbar setPlaceholder:@"City or AirfIEld"];    [self.searchController.searchbar sizetoFit];}

我试图使我的搜索控制器处于活动状态,调用[self.searchController.searchbar becomeFirstResponder]并直接调用searchbarSearchbuttonClicked,但没有任何作用.

解决方法 试着打电话
[self.searchController setActive:YES]

之前

[self.searchController.searchbar becomeFirstResponder]

如果上述方法无效,请尝试以下方法:

- (voID)vIEwDIDLoad {    [super vIEwDIDLoad];    ...    [self initializeSearchController];    ....}- (voID)vIEwDIDAppear:(BOol)animated {    [super vIEwDIDAppear:animated];    [self.searchController setActive:YES];    [self.searchController.searchbar becomeFirstResponder];}- (voID)initializeSearchController {    self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];    self.searchController.searchResultsUpdater = self;    self.searchController.dimsBackgroundDuringPresentation = NO;    self.searchController.delegate = self;    self.searchController.searchbar.delegate = self;    [self.searchController.searchbar sizetoFit];    [self.tableVIEw settableheaderVIEw:self.searchController.searchbar];    self.definesPresentationContext = YES;}
总结

以上是内存溢出为你收集整理的ios – 使UISearchController搜索栏自动激活全部内容,希望文章能够帮你解决ios – 使UISearchController搜索栏自动激活所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1101896.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存