iOS8中的UISearchBar自定义InputView崩溃

时间:2014-09-23 07:10:09

标签: uitextfield ios8 uisearchbar

我使用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中崩溃。

我该如何解决?

1 个答案:

答案 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];
    }