iOS 7升级后,UISearchbar中的UItextField失败 [英] UItextField within UISearchbar failing after iOS 7 upgrade
本文介绍了iOS 7升级后,UISearchbar中的UItextField失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个用于UISearchBar的UITextField,它在iOS 7升级之前有效,现在它在此行失败: UITextField * textfield =(UITextField *)[[searchBar subviews] objectAtIndex:1];
I have a UITextField for the UISearchBar which this was working until iOS 7 upgrade and now it fails at this line: UITextField *textfield=(UITextField*)[[searchBar subviews] objectAtIndex:1];
任何想法如何解决这个问题?谢谢
any idea how to fix this? thanks
// search bar
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0, 0.0, 190.0, 44.0)];
searchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
UIView *searchBarView = [[UIView alloc] initWithFrame:CGRectMake(90.0, 0.0, 230.0, 44.0)];
searchBarView.autoresizingMask = 0;
searchBar.delegate = self;
searchBar.layer.borderColor=[UIColor whiteColor].CGColor;
UITextField *textfield=(UITextField*)[[searchBar subviews] objectAtIndex:1];
[searchBarView addSubview:searchBar];
self.navigationItem.titleView = searchBarView;
推荐答案
试试这个,它在两个 IOS6中都有效和 IOS7 + 和安全的approch
try this , it's work in Both IOS6 and IOS7+ and safe approch
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setFont:[UIFont fontWithName:@"ArialMT" size:10]];
这篇关于iOS 7升级后,UISearchbar中的UItextField失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文