2011-09-29 60 views
0

我已经使用以下代码在我的iPad应用程序的表格中添加了UISearchBar。该表位于我的分割视图控制器的左侧。以编程方式添加UISearchBar - Bar在启动时关闭屏幕 - iPad

问题是,当应用程序启动搜索栏是奇怪的离屏幕左 - 你可以看到它的最后几个像素。如果你点击它,或者向下滚动并返回,它会自行恢复,看起来应该如此。

任何人都可以提出如何解决这个问题吗?

感谢

searchBar = [[UISearchBar alloc] init]; 
self.tableView.tableHeaderView = searchBar; 

searchController = [[UISearchDisplayController alloc] 
        initWithSearchBar:searchBar 
        contentsController:self]; 

searchBar.delegate = self; 
searchController.delegate = self; 
searchController.searchResultsDelegate=self; 
searchController.searchResultsDataSource=self; 

回答

3

你可以尝试使用像框架创建的UISearchBar:

CGRect searchViewFrame = CGRectMake(33, 33, 264, 31); 

或任何尺寸或起源。

像其他资源,你可以一个UIView内创建的UISearchBar,这UIView的添加到的UITableView:

UIView *containerSearch = [[UIView alloc] initWithFrame: searchViewFrame]; 
searchBar = [[UISearchBar alloc] init]; 
[containerSearch addSubview: searchBar]; 
self.tableView.tableHeaderView = containerSearch;