本文介绍了UISearchBar的自定义InputView在iOS7中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在UISearchBar中设置我的自定义inputView。
I need to set my custom inputView in UISearchBar.
所以我编写了以下代码,这在iOS5和iOS6中完美运行。
So i wrote following codes , that is working perfectly in iOS5 and iOS6 .
然而它在iOS7中不起作用。
However it doesn't work in iOS7.
for(int i =0; i<[self.searchBar.subviews count]; i++) {
if([[self.searchBar.subviews objectAtIndex:i] isKindOfClass:[UITextField class]])
{
[(UITextField*)[searchBar.subviews objectAtIndex:i] setFont:[UIFont fontWithName:@"MyCustomFont" size:15]];
UITextField* search=(UITextField*)[searchBar.subviews objectAtIndex:i];
search.delegate = self;
[(UITextField*)[self.searchBar.subviews objectAtIndex:i] setInputView:self.customKeyboard];
[self.customKeyboard setTextView:search];
}
}
[self.sBar reloadInputViews];
我该怎么做?
推荐答案
在iOS7中更改了searchBar子视图层次结构,请尝试以下操作:
The searchBar sub views hierarchy has been changed in iOS7, try the below:
iOS7:
NSArray *searchBarSubViews = [[self.searchBar.subviews objectAtIndex:0] subviews];
iOS6 以及之前:
NSArray *searchBarSubViews = self.searchBar.subviews;
尝试以下更新功能:
NSArray *searchBarSubViews = [[self.searchBar.subviews objectAtIndex:0] subviews];
for(int i =0; i<[searchBarSubViews count]; i++) {
if([[searchBarSubViews objectAtIndex:i] isKindOfClass:[UITextField class]])
{
UITextField* search=(UITextField*)[searchBarSubViews objectAtIndex:i];
[search setFont:[UIFont fontWithName:@"MyCustomFont" size:15]];
search.delegate = self;
[search setInputView:self.customKeyboard];
[self.customKeyboard setTextView:search];
}
}
[self.sBar reloadInputViews];
这篇关于UISearchBar的自定义InputView在iOS7中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!