UISearchbar not displaying in table
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.
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.
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!
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.
精彩评论