UISearchbar 未显示在表格中
我有一个 UISearchbar
我试图在表标题中显示。但由于某些原因,它没有被显示。
我使用以下代码:
self.tableView.tableHeaderView = searchbar;
即使它没有给出任何错误,我也无法在表中看到搜索栏。
我已经实现了 UISearchBarDelegate 并尝试了普通表和分组表。我也尝试过用笔尖。
实际上,同样的事情在其他项目中起作用,我将其导入到我的项目中,但它目前不起作用。
请帮我。谢谢。
I have a UISearchbar
that I am trying to display in table header. But for some reasons it is not getting displayed.
I use the following code:
self.tableView.tableHeaderView = searchbar;
Even though it does not give any error, I am unable to see the search bar in the table.
I have implemented the UISearchBarDelegate
as well as tried both plain and grouped tables. I have also tried with nib.
Actually the same thing was working in other project and I imported this into my project, where it is currently not working.
Please help me. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
听起来也许在您的代码中
self.tableView
或searchbar
为零。当从另一个项目引入代码但忘记将代码正确连接到笔尖时,通常会发生这种情况。It sounds like perhaps in your code either
self.tableView
orsearchbar
is nil. This sort of thing often happens when code is brought in from another project but one forgets to hook things up to the nib correctly.当我将 UIsearchBar 代码导入到我的项目中时,我遇到了同样的问题。
我是这样解决的:
在您的 ViewDidLoad 方法中,只需在此行之前添加这 3 行 (
self.tableView.tableHeaderView = searchBar;
)并确保在您的 xib 中,您的 searchBar 及其委托已连接到文件的所有者。
它就像一个魅力!
I had the same problem when I imported the UIsearchBar code into my project.
I solved it like this:
In your ViewDidLoad method just add these 3 lines before this line (
self.tableView.tableHeaderView = searchBar;
)And make sure in your xib, your searchBar and its delegate is connected to the File's owner.
And it worked like a charm!
如果将视图控制器设置为选项卡栏控制器的一部分,除了 IB 中的“Class”属性之外,还设置“NIB name”属性。我花了几个小时才弄清楚。
If you set your view controller as a part of tabbar controller, besides "Class" property in IB set the "NIB name" property. It takes me several hours to figure it out.