【发布时间】:2020-02-18 01:43:58
【问题描述】:
在我的视图控制器中,我以编程方式添加了一个搜索栏,它的显示方式完全符合我的要求,但是当我点击它时,我无法在搜索栏上写入/键入任何内容,并且日志上没有错误。 我以同样的方式在另一个视图控制器中添加了搜索栏,它确实有效,但在特定情况下它不起作用。我正在从以前的视图控制器推动这个视图控制器,所以它在左侧有一个导航返回按钮(检查图像)它也可以工作。
在视图控制器中有一个 TableView 和一个 CollectionView 我想添加对表视图的搜索。我想知道将这两者放在同一个视图控制器中是否有任何关系。
添加搜索栏的代码
- (void)viewDidLoad {
//other stuff on view controller
[self setSearchView];
}
-(void)setSearchView{
//searchController is added as a property on .h file
//and all the delegate are also added
//@property (strong, nonatomic) UISearchController *searchController;
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater= self;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.searchBar.delegate = self;
self.navigationController.toolbarHidden=YES;
self.navigationItem.titleView=self.searchController.searchBar;
self.searchController.hidesNavigationBarDuringPresentation = NO;
self.definesPresentationContext = YES;
}
我从前一个视图控制器来到这个视图控制器,并在单击按钮时推动这个视图控制器。我正在使用 nib 文件
按钮动作
- (void)ButtonClicked {
MYNextViewController *nextViewController = [[MYNextViewController alloc] initWithNibName:@"MYNibFileName" bundle:nil];
// I also have a tab bar on the bottom which i am hiding for that view controller when pushing
nextViewController .hidesBottomBarWhenPushed=YES;
[self.navigationController pushViewController:nextViewController animated:YES];
}
任何帮助将不胜感激。希望我说清楚了...
【问题讨论】:
-
尝试使用 view herracy 调试,看看是否有任何东西阻止了搜索栏
-
也许层次结构有问题,我找不到其他任何东西。我会看看..tnx
-
你有没有尝试将
[_ searchController becomeFirstResponder];转换成searchBarTextDidBeginEditing方法 -
是的,我做到了,注意到结果是一样的......虽然 tnx
标签: ios objective-c uisearchbar