![](/img/trans.png)
[英]How to refresh my UITableView with UISearchBar after click of cancel button of UISearchBar?
[英]TableViewController UISearchBar after rotation cancel button not clickable
我有一个TableVieController,它的searchBar定位在self.tableView.tableHeaderView上 。 屏幕旋转时,我只是将框架设置为新的CGRect。 该视图看起来不错,但不幸的是,搜索栏的一半不可单击,取消按钮也不可单击。
那我该如何做呢? 我只能通过创建搜索栏的新实例并分配它来做到这一点,但这不是正确的方法,对吗?
const CGRect CGRECT_TABLE_VIEW_PORTRAIT = { { 0.0f, 0.0f }, { 320.0f, 365.0f } };
const CGRect CGRECT_TABLE_VIEW_LANDSCAPE = { { 0.0f, 0.0f }, { 480.0f, 150.0f } };
- (void)viewDidLoad
{
...
// create search bar
searchBar = [[UISearchBar alloc] initWithFrame:self.tableView.bounds];
[searchBar setTintColor:RGB(168, 212, 255)] ;
searchBar.showsCancelButton = YES;
[searchBar sizeToFit]; // Get the default height for a search bar.
searchBar.delegate = self;
self.tableView.tableHeaderView = searchBar;
self.tableView.frame = CGRECT_TABLE_VIEW_PORTRAIT;
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)
interfaceOrientation duration:(NSTimeInterval)duration {
if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) {
tableView.frame = CGRECT_TABLE_VIEW_LANDSCAPE;
} else {
tableView.frame = CGRECT_TABLE_VIEW_LANDSCAPE;
}
}
我不知道您为什么要尝试轮换处理,这种情况应该自动发生。 这段代码的作用是提供一个可以根据旋转程度进行调整的搜索栏:
- (void)viewDidLoad {
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:self.tableView.bounds];
[searchBar setTintColor:[UIColor colorWithRed:168/255 green:212/255 blue:1 alpha:1]];
searchBar.showsCancelButton = YES;
[searchBar sizeToFit]; // Get the default height for a search bar.
searchBar.delegate = self;
self.tableView.tableHeaderView = searchBar;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.