UISearchbar 未显示在表格中

发布于 2024-10-08 22:11:41 字数 306 浏览 0 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

神回复 2024-10-15 22:11:41

听起来也许在您的代码中 self.tableViewsearchbar 为零。当从另一个项目引入代码但忘记将代码正确连接到笔尖时,通常会发生这种情况。

It sounds like perhaps in your code either self.tableView or searchbar 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.

绿光 2024-10-15 22:11:41

当我将 UIsearchBar 代码导入到我的项目中时,我遇到了同样的问题。

我是这样解决的:
在您的 ViewDidLoad 方法中,只需在此行之前添加这 3 行 (self.tableView.tableHeaderView = searchBar;)

searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 280.0f, 44.0f)]; 
searchBar.delegate = self;
[self.view addSubview: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;)

searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 280.0f, 44.0f)]; 
searchBar.delegate = self;
[self.view addSubview: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!

夏日落 2024-10-15 22:11:41

如果将视图控制器设置为选项卡栏控制器的一部分,除了 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文