Iphone UISearchBar disappears when enabled for multiple tables
I am working on an iphone app.
I have eight tables in a view and only a single table has alpha = 1 at a time depending on which tab at the top of my view is clicked. This works perfectly. I have a search bar that looks through the tables and operates almost perfectly - there are some bugs that I am working on. Currently, my biggest concern is that the first time I click a tab, my search bar appears at the top of the table but if I click away to another tab and then go back to the first tab, my searchbar never appears at the top again. This is the code that I think is relevant.
- (IBAction) updateView {
if (isMens) {
if (isA) {
self.curTbl = 0T开发者_如何学Cable;
0Table.alpha = 1;
1Table.alpha = 0;
2Table.alpha = 0;
3Table.alpha = 0;
4Table.alpha = 0;
5Table.alpha = 0;
6Table.alpha = 0;
7Table.alpha = 0;
self.0Table.tableHeaderView = searchBar;
} else if (isB) {
self.curTbl = 1Table;
0Table.alpha = 0;
1Table.alpha = 1;
2Table.alpha = 0;
3Table.alpha = 0;
4Table.alpha = 0;
5Table.alpha = 0;
6Table.alpha = 0;
7Table.alpha = 0;
self.1Table.tableHeaderView = searchBar;
.
.
.
This method is called every time a tab is clicked. The views update properly but as I said, the search bar is nowhere to be found on a already-clicked tab once I click on a tab that has not been clicked before. It only goes to the latest clicked tab.
Any ideas?
I suspect what's happening is that the UITableView doesn't know that its subview has disappeared, so it assumes that it's still a subview and has been laid out correctly.
Try something like this:
if (isMens) {
self.curTbl.tableHeaderView = nil
if (isA) {
...
精彩评论