我有以下代码可以在iOS5下工作,将UISearchBar放在iPad上UITableView的顶部:
- (void)viewDidLoad
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
CGRect searchViewFrame = CGRectMake(33, 33, 264, 45);
UIView *containerSearch = [[UIView alloc] initWithFrame: searchViewFrame];
searchBar = [[UISearchBar alloc] init];
searchBar.barStyle = UIBarStyleDefault;
[containerSearch addSubview: searchBar];
self.tableView.tableHeaderView = containerSearch;
searchController = [[UISearchDisplayController alloc]
initWithSearchBar:searchBar
contentsController:self];
searchBar.delegate = self;
searchController.delegate = self;
searchController.searchResultsDelegate=self;
searchController.searchResultsDataSource=self;
[searchBar release];
}
在iOS6下但是这段代码表现得很奇怪。当iPad以横向模式启动时,UISearchBar处于屏幕外。在ipad旋转为纵向并返回横向之前,它不会出现在正确的位置。
这只是一个iOS6错误或有关如何修复的建议吗?
谢谢!
答案 0 :(得分:0)
您是否尝试使用框架初始化搜索栏? searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0,0,265,45)];