我使用Custom InputView UISearchBar
。现在我无法在iOS8
中为UISearchBar设置Custom InputView。它正在崩溃。
以下是我为UISearchBar
设置Custom InputView的方法for(int i =0; i<[[[self.sBar.subviews objectAtIndex:0] subviews] count]; i++) {
if([[[[self.sBar.subviews objectAtIndex:0] subviews] objectAtIndex:i] isKindOfClass:[UITextField class]])
{
[[[(UITextField*)[sBar.subviews objectAtIndex:0] subviews] objectAtIndex:i] setFont:[UIFont fontWithName:@"CustomFont" size:15]];
UITextField* search=[[(UITextField*)[sBar.subviews objectAtIndex:0]subviews] objectAtIndex:i];
search.delegate = self;
[[[(UITextField*)[self.sBar.subviews objectAtIndex:0] subviews] objectAtIndex:i] setInputView:MyKeyboard];
}
这是崩溃日志。
Could not load the "" image referenced from a nib in the bundle with identifier "com.company.MyApp"
2014-09-23 13:34:13.816 MyApp[1651:61729] Could not load the "" image referenced from a nib in the bundle with identifier "com.company.MyApp"
它在iOS 7中工作正常但在iOS8中崩溃。
我该如何解决?
答案 0 :(得分:1)
我得到了自己问题的答案。
但您需要先检查iOS版本iOS8
,因为此代码对iOS7
不起作用。
if([systemVersion isEqualToString:@"8"])
{
UITextField *search = (UITextField *)[[[self.sBar.subviews objectAtIndex:0] subviews] objectAtIndex:0];
[search setFont:[UIFont fontWithName:@"MyCustomFont" size:15]];
[search setInputView:self.customKeyboard];
[search setTextColor:[UIColor whiteColor]];
[self.customKeyboard setTextView:search];
[search reloadInputViews];
}