【问题标题】:set location of uisearchbar in uiviewcontroller在 uiviewcontroller 中设置 uisearchbar 的位置
【发布时间】:2014-08-10 15:06:33
【问题描述】:
我正在尝试向我的视图控制器添加一个搜索栏。有很多关于 tableviewcontrollers 的教程,但没有 viewcontrollers。我的问题是(就像在这里的多个其他问题)选择搜索栏时,导航栏向上移动和SexingTableView重叠,但搜索栏不会向上移动。
如果我尝试以编程方式添加它,我可以将它实现到表头:
self.tableView.tableHeaderView = mySearchBar;
在我的 UI 中,搜索栏和表格视图之间有按钮。我希望将 searchBar 设置在导航栏的正下方。我该怎么做?
【问题讨论】:
标签:
ios
tableview
navigationbar
searchbar
searchdisplaycontroller
【解决方案1】:
UIView *searchBar_con=[[UIView alloc]initWithFrame:your_frame];
searchBar_con.backgroundColor=[UIColor clearColor];
UISearchBar *srchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 240 , searchBar_con.frame.size.height)];
srchBar.delegate = self;
[searchBar_con addSubview:srchBar];
UISearchDisplayController *searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:srchBar contentsController:self];
self.searchDisplayController.searchResultsDelegate = self;
self.searchDisplayController.searchResultsDataSource = self;
self.searchDisplayController.delegate = self;
[self.view addSubview:searchBar_con];