此代碼在iOS 6中工作得非常好,但在iOS 7中,textBar在導航欄中爲灰色,並且不可點擊?請參閱本圖片UITextfield不能作爲iOS 7的UISearchBar的子視圖嗎?
什麼可能是錯的區別?我不知道他們有什麼的iOS 7究竟發生變化,不知道從哪裏開始尋找解決這個問題...
/問候
UITextField *sbTextField = (UITextField *)[searchBar.subviews lastObject];
[sbTextField removeFromSuperview];
CGRect rect = searchBar.frame;
rect.size.height = 32;
rect.size.width = 210;
sbTextField.frame = rect;
// [sbTextField setKeyboardType:UIKeyboardTypeNumbersAndPunctuation]; Not working in iOS7
// [sbTextField setPlaceholder:NSLocalizedString(@"HintSearchExercise", nil)]; Not working in iOS 7
[sbTextField setAutoresizingMask:UIViewAutoresizingFlexibleBottomMargin];
[searchBar removeFromSuperview];
UIBarButtonItem *searchBarNavigationItem = [[UIBarButtonItem alloc] initWithCustomView:sbTextField];
[[self navigationItem] setLeftBarButtonItem:searchBarNavigationItem];
爲什麼要從搜索欄中刪除文本字段?混淆標準UI控件的私有子視圖結構從來不是解決問題的好方法。 – rmaddy
我刪除了代碼,我從超級視圖中蹦過搜索欄,結果仍然很亂:http://tinypic.com/view.php?pic=1056r7q&s=5#.UkIjzpKpWrg:/ – user1293618
您需要顯示設置代碼顏色和外觀。您還應該刪除所有更改文本字段佈局的代碼。使用提供的「UISearchBar」API來進行所需的任何調整。不要混淆私人子視圖。 – rmaddy