2014-09-23 83 views
1

我有UISearchBar與自定義InputView。現在我無法在iOS8中爲UISearchBar設置自定義輸入視圖。它正在崩潰。UISearchBar在iOS8中自定義InputView崩潰

這是我如何設置自定義InputView爲的UISearchBar

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

我也面臨同樣的問題,任何機構都可以幫助我解決這個問題。 – jamil 2014-10-13 06:01:17

+0

@Shazad。我回答了我自己的問題,適用於iOS8。覈實! – 2014-10-13 06:19:57

回答

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]; 
    } 
+0

感謝得到it.issue只是代表行。 – jamil 2014-10-13 06:29:29