[英]UITextfield not working as subview to UISearchBar in iOS 7?
This code worked perfectly fine in iOS 6 but in iOS 7 the textfield is gray in the navigationBar, and not clickable? 这段代码在iOS 6中工作得很好,但是在iOS 7中,navigationBar中的文本字段为灰色,并且无法单击? See the difference in this picture
看到这张图片的区别
What may be wrong ? 可能是什么问题? I am not aware of what they have changed exactly in iOS 7 and not sure where to start looking for solving this problem...
我不知道它们在iOS 7中发生了什么变化,也不确定从哪里开始寻找解决此问题的方法...
/Regards /问候
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];
in ios7 [searchBar.subviews lastObject]
is not the text field but instead a UIView
instance that acts as an additional container around the controls. 在ios7中,
[searchBar.subviews lastObject]
不是文本字段,而是一个UIView
实例,它充当控件周围的附加容器。
having the same problem with cocktailicious , i plan to use the following category on UISearchBar
: 与cocktailicious有相同的问题,我计划在
UISearchBar
上使用以下类别:
@interface UISearchBar (Workarounds)
@property (readonly, nonatomic) UITextField *textField;
@end
@implementation UISearchBar (Workarounds)
- (UITextField *)textField
{
for (UIView *view in [self subcontrols]) {
if ([view isKindOfClass:[UITextField class]]) {
return (UITextField *)view;
}
}
return nil;
}
- (NSArray *)subcontrols
{
return self.subviews.count == 1 ? [self.subviews.firstObject subviews] : self.subviews;
}
@end
the - subcontrols
method does the trick here. - subcontrols
方法在这里起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.