[英]Adding UISearchBar into tableView header as subview
I'm trying to add a custom header to UITableView
, that has some buttons and an UISearchBar
.我正在尝试将自定义 header 添加到UITableView
,它有一些按钮和一个UISearchBar
。 The problem is, that when I try to use searchBar I get a message:问题是,当我尝试使用 searchBar 时,我收到一条消息:
setting the first responder view of the table but we don't know its type (cell/header/footer)
Has anyone encounter such problem?有没有人遇到过这样的问题?
Are you adding to the table via:您是否通过以下方式添加到表中:
[self.tableView addSubview:customView]
If so, that could be your error.如果是这样,那可能是你的错误。 Adding subviews to UITableView requires that you add them either as header, footer, or cell explicitly.将子视图添加到 UITableView 需要您将它们显式添加为 header、页脚或单元格。 Try:尝试:
self.tableView.tableHeaderView = customView
Just follow the simple steps here..只需按照此处的简单步骤操作即可。
Use the following delegate method to set it as the header of your table view...使用以下委托方法将其设置为表视图的 header ...
– (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { return self.mySearchBar; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.