Hi: I want to display a section index in an UITableView with a search bar in the table view header (not section header). But the index strip is now overlapping the search bar. Is there an elegant solution to avoid this and let the index start below the table header?
-
1http://stackoverflow.com/questions/556814/changing-the-size-of-the-uisearchbar-textfield . . check out mike's comment – thndrkiss Apr 11 '10 at 12:39
-
thndrkiss: You mean answer. Answers are not comments, and Mike has only posted an answer on that question. – Peter Hosey Apr 11 '10 at 22:26
-
Hi, Sney have you solve this problem ? – iXcoder Apr 02 '11 at 04:31
2 Answers
I realize this answer comes very late, but I had the same problem and searched here and elsewhere. I found good answers here: Changing the size of the UISearchBar TextField?
There are several suggestions, but the one I found most straightforward was to put a UISearchBar and UINavBar in a UIView and pass that view to setTableView. The problem is that the table controls the size of the header view, ignoring any setting you add. So adding the view makes the table happy and you can reach inside and set the search bar size without being interfered with by the table.The UINavBar has the same background styles as the UISearchBar, so fills the extra space in a visually consistent way, though you have to tweak its frame - See below:
UISearchBar searchBar = [[[UISearchBar alloc] initWithFrame:CGRectMake(0, 1, 290, 40)] autorelease];
UIView *searchView = [[[UIView alloc] initWithFrame:CGRectMake(0, 1, 320, 40)] autorelease];
UINavigationBar *navBar = [[[UINavigationBar alloc] initWithFrame:CGRectMake(1, -1, 320, 41)] autorelease]; // same gradient/style as search bar
[navBar setTintColor:[UIColor lightGrayColor]];
[searchView addSubview:navBar];
[searchView addSubview:searchBar];
I add empty strings to indexes array:
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
NSMutableArray *array = [NSMutableArray arrayWithArray:_sortedKeys];
[array insertObject:@"" atIndex:0];
[array insertObject:@"" atIndex:0];
return array;
}

- 129,200
- 40
- 280
- 281

- 49
- 1
-
-
This does not help with larger indexes, as the index will be displayed with round "dots" instead of a series of index entries, and still overlap your view. – RickJansen Jul 22 '13 at 11:18