Ios7 使用标准UITableView控制器,UITableView标题将消失在UINavigationBar下
我在Ios7 使用标准UITableView控制器,UITableView标题将消失在UINavigationBar下,ios7,uiviewcontroller,uitableview,uisearchbar,Ios7,Uiviewcontroller,Uitableview,Uisearchbar,我在UINavigationController中有一个UITableViewController。我添加了一个ui搜索栏作为tableView.header: UISearchBar *searchBar = [UISearchBar alloc] initWithFrame: CGRectMake(0,0,self.tableView.frame.size.width,44.0)]; self.tableView.tableHeaderView = searchBar; 问题:滚动时,ta
UINavigationController
中有一个UITableViewController
。我添加了一个ui搜索栏作为tableView.header
:
UISearchBar *searchBar = [UISearchBar alloc] initWithFrame: CGRectMake(0,0,self.tableView.frame.size.width,44.0)];
self.tableView.tableHeaderView = searchBar;
问题:滚动时,tableHeader在导航栏下消失
我已经尝试过设置navigationController.navigationBar.translucent=NO
,但是使用标准的UITableViewController,这个技巧似乎不起作用
有没有办法使用标准的UITableViewController解决此问题?我希望它的工作原理完全一样,它在联系人应用程序。我的目标是iOS7。我放弃了使用UITableViewController
,我使用了一个标准的UIViewController
,上面有一个UISearchBar
,下面有一个UITableView
。通过设置self.edgesForExtendedLayout=UIRectEdgeNone
搜索开始时,UISearchBar
不会与状态栏重叠:
-(id) initWithTableViewStyle: (int) tableViewStyle
{
self = [super init];
if (self) {
//Set the UITableViewStyle
self.tableViewStyle = tableViewStyle;
//Be sure the searchBar won't overlap the status bar
self.edgesForExtendedLayout = UIRectEdgeNone;
//Add the subviews to the mainView
[self.view addSubview:self.searchBar];
[self.view addSubview:self.tableView];
//Autolayout
//Create the views dictionary
NSDictionary *viewsDictionary = @{@"searchBar":self.searchBar,
@"tableView": self.tableView};
//Create the constraints using the visual language format
[self.view addConstraints:[NSLayoutConstraint
constraintsWithVisualFormat: @"H:|[searchBar]|"
options:0
metrics:nil
views:viewsDictionary]];
[self.view addConstraints:[NSLayoutConstraint
constraintsWithVisualFormat: @"H:|[tableView]|"
options:0
metrics:nil
views:viewsDictionary]];
[self.view addConstraints:[NSLayoutConstraint
constraintsWithVisualFormat:@"V:|[searchBar(==44)][tableView]|"
options:0
metrics:nil
views:viewsDictionary]];
}
return self;
}
-(UITableView*) tableView
{
if (!_tableView){
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0,0,0)
style:self.tableViewStyle];
_tableView.translatesAutoresizingMaskIntoConstraints=NO;
_tableView.delegate = self;
_tableView.dataSource=self;
}
return _tableView;
}
-(UISearchBar*) searchBar
{
if(!_searchBar){
_searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0,0,0,0)];
_searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
_searchBar.translatesAutoresizingMaskIntoConstraints=NO;
_searchBar.translucent = NO;
_searchBar.delegate = self;
}
return _searchBar;
}
UIViewController应制作为:
UIViewController <NSFetchedResultsControllerDelegate,
UISearchBarDelegate,
UISearchDisplayDelegate,
UITableViewDataSource,
UITableViewDelegate>
UIViewController