将UISearchBar作为子视图添加到tableView头中
问题描述:
我正在尝试将自定义标头添加到 UITableView
,它有一些按钮和 UISearchBar
。
问题是,当我尝试使用searchBar时,我收到一条消息:
I'm trying to add a custom header to UITableView
, that has some buttons and an UISearchBar
.
The problem is, that when I try to use searchBar I get a message:
设置表的第一个响应者视图但是我们不知道它的类型(单元格/页眉/页脚)
有没有人遇到过这样的问题?
Has anyone encounter such problem?
答
只需按照这里的简单步骤进行..
Just follow the simple steps here..
- 创建一个属性对于'。''文件中的mySearchBar并进行综合。
- 在viewDidLoad / viewDidAppear方法中设置其属性(或者你可以在界面生成器中完成)
-
使用以下委托方法将其设置为表格视图的标题...
- create a property for mySearchBar in your '.h' file and synthesize.
- set its attributes in viewDidLoad/viewDidAppear method (or u can simply do it in the Interface Builder)
Use the following delegate method to set it as the header of your table view...
– (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
return self.mySearchBar;
}