遇到个奇怪的问题,记录下:
你是否在开发中遇到,searchBar怎么调用这个键盘管理iqkeyboardmanager,为啥你加进去了,就是不显示呢?
对此,我就懵逼了。。。。。
尝试解决
咋办呢,试了下,直接在当前的VC中加入代码让他出来:
大概是这个样子:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[IQKeyboardManager sharedManager].enable = YES;
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[IQKeyboardManager sharedManager].enable = NO;
}
结果,没用,还是没出来。。
继续尝试
对此,我想了一下,难道我要自己定义一个搜索输入框,虽说能解决问题,但是,需要花时间去写,有没有更好的办法呢;
我谷歌了一下,于是乎,有了解决办法:
那就是修改源码:参考: how to get iqkeyboardmanager to include UISearchBar
其实就是,打开这个第三方库,找到这个分类:
IQUIView+Hierarchy.m
第309行,- (void)isSearchBarTextField
将isSearchBarTextField = YES
-> isSearchBarTextField = NO
最终就是这个样子:
-(BOOL)isSearchBarTextField
{
UIResponder *searchBar = [self nextResponder];
BOOL isSearchBarTextField = NO;
while (searchBar && isSearchBarTextField == NO)
{
if ([searchBar isKindOfClass:[UISearchBar class]])
{
isSearchBarTextField = NO;
break;
}
else if ([searchBar isKindOfClass:[UIViewController class]]) //If found viewcontroller but still not found UISearchBar then it's not the search bar textfield
{
break;
}
searchBar = [searchBar nextResponder];
}
return isSearchBarTextField;
}
然后,run,It's OK;
网友评论